home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Toolbox / System 7.0 WDEF / StandardWDEF.a
Encoding:
Text File  |  1991-04-03  |  82.8 KB  |  2,348 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        StandardWDEF.a
  3. ;
  4. ;    Contains:    This file contains the window definition procedure
  5. ;                 "DocumentProc", the standard Mac window type.
  6. ;                  It is a rectangular window with a title bar.
  7. ;           ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  8. ;            •••••••••••••>>>> IMPORTANT!!! <<<<<<<<•••••••••••••••••••••••••••
  9. ;            ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  10. ;            THESE ARE NOT FINAL!!!! This is the WDEF for Beta 4 System 7.  The 
  11. ;            final WDEF may (will) be slightly or greatly different from this!
  12. ;            This is provided for your information only, to see how to write your
  13. ;            application's WDEFs to match System 7.
  14. ;    Copyright:    © 1982-1991 by Apple Computer, Inc., all rights reserved.
  15. ;
  16.             STRING        ASIS
  17.  
  18.             PRINT        OFF
  19.             PRINT        ON
  20.  
  21.  
  22.  
  23. ; ================================================
  24. ; REGISTERS
  25. ; ================================================
  26. ; registers being used and need to be preserved
  27.  
  28. rectReg        EQU        A4            ; rectangle’s address is kept in reg
  29. windowReg    EQU        A3            ; window pointer address is kept in reg
  30. titleHgtReg    EQU        D7            ; window’s title bar height in reg
  31. paramReg    EQU        D6            ; parameter passed in function call
  32. varCodeReg    EQU        D5            ; varCode passed in funciton call
  33.  
  34. ; ================================================
  35. ; CONSTANTS
  36. ; ================================================
  37.  
  38. HiliteFlagGlobal    EQU        $B20    ; low memory with hiliting flag
  39. HiliteFlagBit        EQU        0        ; bit 0 in HiliteFlagGlobal byte
  40.  
  41. hasZoom     EQU     3            ; bit 3 is zoom bit
  42. hasGrow     EQU     2            ; bit 2 is grow bit
  43.  
  44. IconSize    EQU        20            ; width of small icon in title
  45. minTitleH    EQU        19            ; minimum title bar height without SICN
  46. minTitleHIcon EQU    21            ; minimum title bar height with SICN
  47.  
  48. dboxWithTitle    EQU        5        ; proc ID of dBoxProc with title bar
  49. dBoxBorderSize     EQU        7        ; dBoxProc border size
  50. proc5TopAdjust    EQU        4        ; title and border share some area
  51. proc5HitZAdjust    EQU        6        ; zoom box is more to the left
  52. scrollBarSize    EQU        16        ; size of scroll bar area
  53.  
  54. wHiliteLight        EQU        5
  55. wHiliteDark            EQU        6
  56. wTitleBarLight        EQU        7
  57. wTitleBarDark        EQU        8
  58. wDialogLight        EQU        9
  59. wDialogDark            EQU        10
  60. wTingeLight            EQU        11    ; For color tinges in title bar & gadgets
  61. wTingeDark            EQU        12
  62.  
  63. lowestShadeIndex    EQU        16
  64. wHiliteShade0        EQU        16
  65. wHiliteShade7        EQU        17
  66. wHiliteShade8        EQU        18
  67. wHiliteShadeA        EQU        19
  68. wHiliteShadeD        EQU        20
  69. wTitleBarShade0        EQU        21
  70. wTitleBarShade1        EQU        22
  71. wTitleBarShade4        EQU        23
  72. wDialogShade0w        EQU        24
  73. wDialogShade4w        EQU        25
  74. wDialogShade6w        EQU        26
  75. wDialogShadeBb        EQU        27
  76. wDialogShadeF        EQU        28
  77. wDialogShade0b        EQU        30
  78. wDialogShade4b        EQU        31
  79. wDialogShade6b        EQU        32
  80. wDialogShadeBw        EQU        33
  81. wLTinge0            EQU        34
  82. wLTinge4            EQU        35
  83. wDTingeF            EQU        36
  84.  
  85. wZoomGadget            EQU        0
  86. wGoAwayGadget        EQU        1
  87. wZoomHilitedGadget    EQU        2
  88. wGoAwayHilitedGadget    EQU        3
  89. wGrowGadget            EQU        4
  90.  
  91. kPixmapID            EQU        -14336
  92. kHighlightPix        EQU        -14334
  93.  
  94. minWCTBDepth        EQU        4
  95. minColorDepth        EQU        8
  96.  
  97.  
  98. ;  fakeDeviceFlags is used when we bypass DeviceLoop and draw the grow icon directly, and we’re
  99. ; on a machine that doesn’t have Color QuickDraw.
  100.  
  101. fakeDeviceFlags        equ        $A801
  102.  
  103.  
  104. ; ================================================
  105. ; TYPES
  106. ; ================================================
  107. ; There records are only types, they do not allocate space
  108. ; ------------- FontInfo record TYPE -------------
  109. WInfoRec    RECORD    0                ; FontInfo record type
  110. WAscent        ds.w    1
  111. WDescent    ds.w    1
  112. WHeight        ds.w    1
  113. WBoxDelta    ds.w    1
  114.             ENDR
  115.  
  116. ; ------------- RGBInfo record TYPE -------------
  117. RGBInfoRec    RECORD    0                ; RGBColor record type
  118. red            ds.w    1
  119. green        ds.w    1
  120. blue        ds.w    1
  121.             ENDR
  122.  
  123. WDefDrawFrame    RECORD    0                ; stack frame for DeviceLoop draw proc
  124. retAddress        ds.l    1                ; return address
  125. StartParams        EQU        *
  126. userData        ds.l    1                ; long we passed to DeviceLoop
  127. devHandle        ds.l    1                ; GDevice handle
  128. deviceFlags        ds.w    1                ; flags for current device
  129. depth            ds.w    1                ; bits/pixel for this call
  130. ParamSize        EQU        *-StartParams
  131.                 ENDR
  132.  
  133.  
  134. ; ================================================
  135. WDEF0        PROC        EXPORT
  136. ; ================================================
  137.  
  138. ; FUNCTION MyWindow(varCode: INTEGER; window: WindowPtr;
  139. ;                    message: INTEGER; param: LongInt): LongInt
  140.  
  141. ; Create a stack frame recode that matches the above function.
  142. ; The parameters passed on the stack are between ParamBegin and ParamSize.
  143. ; ParamSize the number of bytes to be removed (poped) off the stack after
  144. ; the UNLINK instruction.  Any local variables to be created are listed
  145. ; between A6Link and LinkSize.  LinkSize is the size of the entire stack
  146. ; frame and it the number of bytes used in the LINK instruction.  To add
  147. ; more local variables, insert it between A6Link and LinkSize.
  148.  
  149. StackFrame    RECORD    {A6Link},DECR    ; build a stack frame record
  150. ProcResult    ds.l    1                ; function’s result returned to caller
  151. ParamBegin    EQU    *                    ; start parameters after this point
  152. ;            parameters on stack
  153. varCode        ds.w    1                ; variation code
  154. window        ds.l    1                ; the window pointer
  155. message        ds.w    1                ; operation to perform
  156. param        ds.l    1                ; addition information based on message
  157. ParamSize    EQU        ParamBegin-*    ; size of all the passed parameters
  158. RetAddr     ds.l    1                ; place holder for return address
  159. A6Link        ds.l    1                ; place holder for A6 link
  160. ;            local variables being allocated
  161. SavFgCol    ds        RGBInfoRec        ; saved WMgrCPort ForeColor (color only)
  162. SavBkCol    ds        RGBInfoRec        ; saved WMgrCPort BackColor (color only)
  163. WInfo        ds        WInfoRec        ; record for font and other info
  164. OldPort        ds.l    1                ; current port to be restored
  165. TempRgn        ds.l    1                ; temporary region handle
  166. AuxCTab        ds.l    1                ; handle to auxCTable (color only)
  167. AuxCPtr        ds.l    1                ; pointer to auxCTable (color only)
  168. IsColor        ds.b    1                ; have colorQD in toolbox? [boolean]
  169. IsTitleIcon    ds.b    1                ; do we have an icon in the title bar?
  170. IsProcFive    ds.b    1                ; dBox with title bar? [boolean]
  171. threeDWind    ds.b    1                ; conditions right for System 7 windows?
  172. curDepth    ds.l    1                ; current drawing depth for SetupColor
  173. startRGB    ds.w    3
  174. endRGB        ds.w    3
  175. tempRGB        ds.w    3
  176. workPixMap    ds.l    1
  177. gadgetHighlight    ds.w    1
  178. tempPixels    ds.l    1
  179. globalOffset    ds.l    1            ; Amount to offset when drawing grow icon in WMgrPort
  180. curZone        ds.l    1                ; temporary storage for theZone 
  181. bogusCtab    ds.l    1                ; handle to bogus color table                            
  182. LinkSize    EQU     *                ; size of all the local variables
  183.             ENDR
  184.  
  185.  
  186. ; ================================================
  187. ; MAIN entry point in the WDEF.
  188. ; ================================================
  189. ; Jump over the defined data and get to the code.
  190.  
  191. DocProc        bra.s    WDEFStart            ; and a way we go
  192.  
  193.  
  194. ; Define in the code segment necessary data.  The standard header
  195. ; is first then additional data used in the WDEF.
  196.  
  197.             dc.w    0                    ; flags word
  198.             dc.b    'WDEF'                ; resource type
  199.             dc.w    0                    ; resource ID
  200.             dc.w    15                    ; version number
  201.  
  202.  
  203. ; ================================================
  204. WDEFStart                                ; start of the WDEF code
  205. ; ================================================
  206.             WITH    StackFrame            ; cover our local stack frame
  207.             LINK    A6,#LinkSize         ; set stack frame to address params
  208.             moveM.l D3-D7/A1-A4,-(SP)    ; save work registers
  209.             clr.l    ProcResult(A6)        ; initialize funtion’s result
  210.  
  211. ; test if the message is in range
  212.  
  213.             cmp.w    #wGIconMsg,message(A6)    ; compare to highest value             
  214.             BGT     WDEFEnd                    ; skip it, it’s too high             
  215.             cmp.w    #wDrawMsg,message(A6)    ;  compare to lowest value, too         
  216.             BMI     WDEFEnd                    ;
  217.  
  218.             move.l    (A5),A0             ; get pointer to QuickDraw globals
  219.             move.l    (A0),OldPort(A6)    ; save current port
  220.  
  221. ; ------------- fetch the parameters -------------
  222.  
  223.             move.l    window(A6),windowReg ; get the window pointer
  224.             lea     TempRect,rectReg    ; get TempRect address in a reg
  225.             move.l    param(A6),paramReg    ; get the param    in a reg
  226.             move.w    varCode(A6),varCodeReg    ; get the selector integer
  227.             AND.w     #3,varCodeReg        ; ignore "inGrow" variant
  228.  
  229. ; ------------- is the dBox with title? -------------
  230. ; determine if this is a dBoxProc using a title
  231.  
  232.             move.w    varCode(A6),D0        ; get real selector
  233.             AND.w    #7,D0                ; AND off higher bits
  234.             cmp.w    #dboxWithTitle,D0    ; compare against new proc
  235.             SEQ.b    IsProcFive(A6)        ; set if dBox with title
  236.  
  237. ; ------------- Determine type of system -------------
  238. ; We need to know if we have color QuickDraw and a color window manager port.
  239.  
  240.             cmp.w    #$3FFF,ROM85        ; do we have color QD?
  241.             SLS        IsColor(A6)            ; set boolean depending on color or B&W system
  242.             BLS.s    @ColorSys            ; this system has color QD
  243.  
  244.             move.l    WMgrPort,-(SP)        ; B&W, set to window manager port
  245.             _SetPort                    ;
  246.             bra.s    @CommonSys            ; done for the B&W environment
  247.  
  248. ; ------------- doin it with color -------------
  249. ; when using the WMgrCPort, it is the defproc’s responsibility to reconcile
  250. ; the WMgrPort and the WMgrCPort.  Also find the auxWinRec and lock it down
  251. ; This compares the pertinent fields of the WMgrPort and the WMgrCPort,
  252. ; updating the WMgrCPort as necessary to match the WMgrPort.
  253.  
  254. @ColorSys    move.l    WMgrCPort,-(SP)        ; make the WMgrCPort the current port
  255.             _SetPort                    ; set it
  256.             move.l    WMgrPort,A0            ; get the WMgrPort addr
  257.             move.l    WMgrCPort,A1        ; and the WMgrCPort too
  258.             pea        bkPat(A0)            ; push pointers to pattern for later
  259.             pea        pnPat(A0)            ;
  260.                                         ; copy all fields from pnLoc to end of grafPort,
  261.                                         ; excluding pnPixPat and fillPixPat
  262.             lea        pnLoc(A0),A0                ; point at source
  263.             lea        pnLoc(A1),A1                ; point at dest
  264.             move.l    (A0)+,(A1)+                    ; copy pnLoc
  265.             move.l    (A0)+,(A1)+                    ; copy pnSize
  266.             move.w    (A0)+,(A1)+                    ; copy pnMode
  267.             addq    #8,A0                        ; skip pnPat (aka, pnPixPat,fillPixPat)
  268.             addq    #8,A1                        ;
  269.             move.w    #((portRec-pnVis)/2)-1,D0    ; set up a counter (long sized)
  270. @1            move.w    (A0)+,(A1)+                    ; copy it
  271.             Dbra    D0,@1                        ; loop
  272.                                                 ; now set up the patterns in the WMgrCPort
  273.             _PenPat                                ; (which is thePort) the parameters were
  274.             _BackPat                            ; pushed before the copying loop above
  275.  
  276.             pea        SavFgCol(A6)        ; push a pointer to save area
  277.             _GetForeColor                ; get the current color
  278.             pea        SavBkCol(A6)        ;
  279.             _GetBackColor                ;
  280.             move.l    #blackColor, -(SP)    ; set default colors
  281.             _ForeColor
  282.             move.l    #whiteColor, -(SP)
  283.             _BackColor
  284.  
  285. ; ------------- get auxWinRec -------------
  286.  
  287.             clr.l    -(SP)                ; here’s a space for the var handle
  288.             clr.w    -(SP)                ; function return here
  289.             move.l    windowReg,-(SP)        ; push window ptr
  290.             pea        6(SP)                ; a pointer to the space above
  291.             _GetAuxWin                    ; find the auxrec
  292.             addq    #2,SP                ; pitch the boolean (it doesn’t matter)
  293.             move.l    (SP)+,A0            ; get the auxRecHandle
  294.             move.l    (A0),A0                ; handle -> ptr
  295.             move.l    awCTable(A0),A0        ; get the colortable handle
  296.             move.l    A0,AuxCTab(A6)        ; save this handle
  297.             _HLock                        ; lock the table down in memory
  298.             move.l    (A0),AuxCPtr(A6)    ; and get a pointer too!
  299.  
  300. ; ------------- setup window info -------------
  301. ; Get the font info for this window.  Put the height of the title bar in
  302. ; titleHgtReg and wHeight(A6).  Put distance of the top of the goaway box
  303. ; from the top of the bar in WBoxDelta(A6).
  304. ;
  305.  
  306. @CommonSys    pea        WInfo(A6)            ; push pointer to a FontInfoRec
  307.             _GetFontInfo                ; and get the font’s info
  308.             move.w    WInfo.wAscent(A6),titleHgtReg ; get font ascent
  309.             add.w    WInfo.wDescent(A6),titleHgtReg ; add descent
  310.             addq.w    #4,titleHgtReg        ; get the height
  311.             BSET    #0,titleHgtReg        ; make height odd for symmetry
  312.             moveq    #minTitleH,D1        ; get min title height for no icon
  313.  
  314.             cmp.w    D1,titleHgtReg        ; force height to minimum
  315.             bge.s    @3                    ; => not a tiny font
  316.             move.w    D1,-(SP)            ; save min title height on stack
  317.             sub.w    titleHgtReg,D1        ; how much less than minimum is it?
  318.             LSR.w    #1,D1                ; used for centering tiny fonts
  319.             add.w    D1,WInfo.wAscent(A6) ; make the ascent "bigger"
  320.             move.w    (SP)+,titleHgtReg    ; pop min title height
  321. @3            move.w    titleHgtReg,WInfo.wHeight(A6) ; WHeight=ascent+descent+2
  322.             move.w    titleHgtReg,D0        ; get height
  323.             sub.w    #13,D0                ; subtract height of box
  324.             LSR.w    #1,D0                ; divide by 2
  325.             move.w    D0,WInfo.wBoxDelta(A6) ; save delta to goAway box
  326.  
  327. ; ------------- create a temp region -------------
  328.  
  329.             clr.l    -(SP)                ; create a temp region
  330.             _NewRgn                     ; get a new region
  331.             move.l    (SP)+,TempRgn(A6)    ; and save in our frame
  332.  
  333. ; ------------- get a pixmap for drawing the gadgets ------------
  334.  
  335.             subq.l    #4, SP                    ; room for a PixMapHandle
  336.             move.l    #'pmap', -(SP)            ; the Pixmap resource type
  337.             move.w    #kPixmapID, -(SP)        ; ID of working pixmap
  338.             _GetResource
  339.             move.l    (SP)+, workPixmap(A6)    ; save it for later
  340.             move.l    #16,D0                    ; allocate a bogus ctab                         
  341.             _NewHandle    ,SYS,CLEAR            ;    in sys heap with 0 entries                    
  342.             move.l    A0, bogusCtab(A6)        ; store the ctab so that we can dispose of it    
  343.             move.l    workPixmap(A6),A0        ; get the pixmap                                
  344.             move.l    (A0),A0                    ; get ptr to pixmap                                
  345.             move.l    bogusCtab(A6),pmTable(A0)    ; put the bogus ctab in our pixmap            
  346.             clr.l    tempPixels(A6)            ; init this to NIL
  347.  
  348. ; ------------- go handle the message -------------
  349.  
  350.             move.w    message(A6),D0        ; get message
  351.             ADD     D0,D0                ; double for word index
  352.             lea     GoDocProc,A0        ; get jump table address
  353.             add.w    GoDocProc(D0),A0    ; compute dispatch address
  354.             jsr     (A0)
  355.  
  356. ; ------------- prepare to exit WDEF -------------
  357. ; Dispose of all data allocated and restore port
  358.  
  359.             move.l    bogusCtab(A6),A0    ; Dispose the bogus Color table                        
  360.             _DisposHandle                ;
  361.             move.l    TempRgn(A6),-(SP)    ; dispose of temp region
  362.             _DisposRgn                    ;
  363.             tst.b    IsColor(A6)            ; are we on a color system?
  364.             beq.s    @NoColor2            ; if on B&W, then skip
  365.  
  366. ; ------------- color clean up -------------
  367. ; unlock the color table and restore the fore- and backColors                                     
  368.  
  369.             move.l    AuxCTab(A6),A0        ; get the colortable handle
  370.             _HUnlock                    ; release it
  371.             pea        SavBkCol(A6)        ; pointer to RGBColor
  372.             _RGBBackColor                ;
  373.             pea        SavFgCol(A6)        ; pointer to RGBColor
  374.             _RGBForeColor                ;
  375. @NoColor2                                ; END OF A COLOR-ONLY SECTION
  376.  
  377.             move.l    OldPort(A6),-(SP)    ; restore previous port
  378.             _SetPort
  379.  
  380. ; ------------- End of WDEF -------------
  381. WDEFEnd                                    ; ‘Out Of Range, of course’
  382.             moveM.l (SP)+,D3-D7/A1-A4    ; restore work registers
  383.             UNLK    A6                    ; unlink stack frame
  384.             move.l    (SP)+,A0            ; get return address
  385.             ADD     #ParamSize,SP        ; strip parameters
  386.             jmp     (A0)                ; return to caller
  387.  
  388.  
  389. ; ------------- WDEF message jump table -------------
  390. ; dispatch table -- entries must be long branches!
  391.  
  392. GoDocProc    dc.w    DrawDoc-GoDocProc    ; draw is message #0
  393.             dc.w    HitDoc-GoDocProc    ; hit test is message #1
  394.             dc.w    CalcDoc-GoDocProc    ; calc test is message #2
  395.             dc.w    InitDoc-GoDocProc    ; init is message #3
  396.             dc.w    DisposeDoc-GoDocProc ; dispose is message #4
  397.             dc.w    GrowDoc-GoDocProc    ; grow message is #5
  398.             dc.w    DrawGIcon-GoDocProc ; draw grow icon is #6
  399.  
  400. ; ================================================
  401. ; wNew message
  402. ; ================================================
  403. ; InitDoc is used to initialize our zoom size and title icon handle
  404. ; Need to make sure the goAway is ignored if the application tried to
  405. ; set this flag.  Changing this here will change the window record.
  406. ; The application could set the goAway flag after creating the window,
  407. ; but that doesn’t seem likely to happen.
  408.  
  409. InitDoc
  410.             tst.b    IsProcFive(A6)        ; dBoxProc with title bar?
  411.             beq.s    @KeepGoAway            ; no, don’t touch goAway flag
  412.             clr.w    wGoAway(windowReg)    ; yes, then clear the flag out
  413. @KeepGoAway
  414.             moveq    #8+8,D0                ; space for 2 rects
  415.  
  416.             _NewHandle ,clear            ; allocate the space
  417.             move.l    A0,wDataHandle(windowReg)    ; save handle to data
  418.             beq.s    InitDone                    ; => not able to get space
  419.  
  420.             move.w    varCode(A6),D0
  421.             Btst    #hasZoom,D0            ; does it want a zoom box?
  422.             beq.s    InitDone            ; no, then we’re done
  423.  
  424. ; ------------- initialize userState and stdState -------------
  425. ; set default zoom data.  Consists of 2 rects: SmallSize, BigSize
  426. ; get the size of the zoomed out window in global coordinates.    To do this,
  427. ; pull the screen size from screenbits.bounds and indent a little.
  428.  
  429.             addq.b    #1,wZoom(windowReg)    ; set zoom flag to TRUE
  430.             move.l    (A0),A2             ; point to data
  431.             addq.w    #8,A2                ; point to bigSize
  432.             move.l    GrafGlobals(A5),A1    ; point to QuickDraw globals
  433.             move.l    screenBits+bounds(A1),(A2)+     ; get topLeft
  434.             move.l    screenBits+bounds+4(A1),(A2)+    ; get botRight
  435.             moveq    #3,D0                            ; get indent
  436.  
  437. ; Zooming the dBoxProc with a title.  Here I set the alternate size to be
  438. ; further inset of the screen.  This doesn’t take into account the
  439. ; normal zoomable windows have a shadow and this causes the proc=5 to be
  440. ; zoomed out one pixel short on the right edge.  Also, since proc=5 shares
  441. ; a portion of the title area with the fancy border of the content this
  442. ; makes the title bar zoom a few pixels lower than normal window.
  443. ; Applications using this window are suppose to manually set the alternate
  444. ; size anyway, so I’m not too concerned about this.
  445.  
  446.             tst.b    IsProcFive(A6)        ; dBoxProc with title bar?
  447.             beq.s    @1                    ; no, use normal sizing
  448.             addq.w    #dBoxBorderSize,D0    ; add fancy border to sizing
  449.  
  450. ; ------------- inset stdState based on indentation -------------
  451. @1
  452.             sub.w    D0,-(A2)            ; indent right
  453.             sub.w    D0,-(A2)            ; indent bottom
  454.             add.w    D0,-(A2)            ; indent left
  455.             add.w    D0,-(A2)            ; indent top
  456.             move.w    MBarHeight,D0         ; get menu bar height
  457.             add.w    D0,(A2)                ; past menu bar height
  458.             add.w    titleHgtReg,(A2)     ; and past window title
  459.  
  460.             move.l    (A0),rectReg         ; point at userState
  461.             bsr        GetRect                ; convert rect to global
  462. InitDone    rts
  463.  
  464.  
  465. ; ================================================
  466. ; wDispose message
  467. ; ================================================
  468. ; DisposeDoc is called when the window is being closed.  All we need to do is
  469. ; give back the handle we borrowed.
  470.  
  471. DisposeDoc
  472.             move.l    wDataHandle(windowReg),D0    ; a data handle?
  473.             beq.s    DisposeDone            ; no, then we’re done
  474.  
  475.             move.l    D0, A0                ; get data handle
  476.             _DisposHandle                ; release it, ignoring errors
  477.  
  478. DisposeDone    rts
  479.  
  480.  
  481. ; ================================================
  482. ; wDraw message
  483. ; ================================================
  484. ; DrawDoc -- draw the document window.   The windowPtr is in windowReg
  485. ; First test for a EORGoAway call and special case it
  486. ; Put shadowing about into D4.
  487.  
  488. DrawDoc        tst.b    wVisible(windowReg)        ; is it visible?
  489.             beq     @exitDrawDoc             ; if not, don’t do anything
  490.  
  491. ; ------------- set up shadow -------------
  492.  
  493.             _PenNormal                    ; we want the normal pen
  494.             move.l    OneOne,D4            ; get shadow factor, assume 1,1
  495.             tst.w    varCodeReg            ; documentProc?
  496.             beq.s      @1                    ; if so, we’re cool
  497.  
  498.             add.l    D4,D4                ; double the shadow to 2,2
  499.             cmp.w    #3,varCodeReg        ; does it have shadow?
  500.             beq.s      @1                    ; if so, we’re cool
  501.             moveq    #0,D4                ; otherwise no shadow
  502.  
  503. @1
  504.             move.l    structRgn(windowReg), -(SP)
  505.             pea        WDefDrawWindow        ; address of devloop drawing proc
  506.             clr.l    -(SP)                ; no unusual activities
  507.             clr.l    -(SP)                ; and no user data
  508.             _DeviceLoop
  509. ; DeviceLoop is a new call for System 7.0, that iterates through all the current gDevices and
  510. ; sees if the region you passed is on a specific device.  If it is, it calls the drawing proc
  511. ; you passed.  It does lots of other neat things for you also, see the Device Manager chapter
  512. ; of Inside Mac VI for a full description of this call.
  513.             cmp.w     #wInGoAway,paramReg ; was it an XOR call?
  514.             blt     @exitDrawDoc        ; if not, don’t invert state bit
  515.             eor.b    #1<<HiliteFlagBit, HiliteFlagGlobal
  516.  
  517. @exitDrawDoc
  518.             rts
  519.  
  520.  
  521. WDefDrawWindow
  522.  
  523.             with    WDefDrawFrame
  524.  
  525.             move.w    depth(SP), curDepth(A6)    ; save this for SetupColor magic
  526.             move.l    devHandle(SP), D1        ; pass this drawing device
  527.             bsr        CheckAvailableColors    ; see if we have enough colors
  528.  
  529.             cmp.w     #wInGoAway,paramReg ; is it a goAway call?
  530.             bge     EORStuff            ; if so, go handle it
  531.  
  532.             bclr    #HiliteFlagBit, HiliteFlagGlobal    ; otherwise, init hilite flag
  533.  
  534. ; ------------- frame the window’s body -------------
  535.  
  536.             tst.b    wHilited(windowReg)    ; Is window highlighted?
  537.             bz.s    @inactiveFrame        ; don’t draw shaded title bar
  538.             moveq    #wFrameColor,D0        ; get fore color
  539.             bra.s    @frameShadeCorrect
  540. @inactiveFrame
  541.             moveq    #wHiliteShadeA,D0        ; Get fore color
  542. @frameShadeCorrect
  543.             moveq    #wContentColor,D1    ; get back color
  544.             bsr        SetupColors            ; set ’em up
  545.  
  546.             bsr        StructInTemp        ; get StrucRgn.rgnBBox in rectReg
  547.             sub.l    D4,botRight(rectReg) ; inset botRight to ignore shadow
  548.             move.l    rectReg,-(SP)        ; push rect address
  549.             _FrameRect                    ; frame the body
  550.  
  551.             cmp.l    #0,D4                ; any drop shadow?
  552.             beq.s    NoDrop                ; if not, skip
  553.  
  554. ; ------------- draw the drop shadow -------------
  555. ; paint the drop shadow, shadow amount in D4
  556.  
  557.             moveq    #wFrameColor,D0        ; Draw drop shadow with frame color always
  558.             bsr        SetupForeColor
  559.  
  560.             move.l    D4,-(SP)            ; push shadow factor
  561.             _PenSize                    ; make penSize = shadow factor
  562.             move.w    right(rectReg),-(SP) ; push right
  563.             move.w    top(rectReg),-(SP)    ; push top
  564.             add.w    D4,(SP)                ; add shadow factor
  565.             _MoveTo                     ; MoveTo(right,top+shadow)
  566.             move.w    right(rectReg),-(SP) ; push right
  567.             move.w    bottom(rectReg),-(SP) ; push bottom
  568.             _LineTo                     ; LineTo(right,bottom)
  569.             move.w    left(rectReg),-(SP)    ; push left
  570.             add.w    D4,(SP)                ; add shadow factor
  571.             move.w    bottom(rectReg),-(SP) ; push bottom
  572.             _LineTo                     ; LineTo(left+shadow,bottom)
  573.             _PenNormal                    ; restore normal pen
  574.  
  575. NoDrop        cmp.w     #1,varCodeReg        ; dBoxProc?
  576.             bne        NotFancy            ; if not, skip
  577.  
  578. ; ------------- draw fancy border -------------
  579. ; draw fancy for dialog box ( only for variant 1).  The code is a little
  580. ; difficult to follow, but it saved some bytes this way.  New feature
  581. ; for a dBoxProc that’s deactive is that it get a gray frame.  Also, I
  582. ; removed the flicker that used to happen when a dBoxProc went deactive.
  583.  
  584. ; In the case of the dBoxProc with title bar, the fancy border needs to
  585. ; consider the title area, and that the bottom of the title area is shared
  586. ; with the fancy border by a few pixels.
  587.  
  588.             tst.b    IsProcFive(A6)        ; dBoxProc with title?
  589.             beq.s    @1                    ; no, then don’t adjust framing
  590.  
  591.             add.w    titleHgtReg,top(rectReg) ; TempRect still in rectReg
  592.              subq.w    #proc5TopAdjust,top(rectReg) ; tweak it
  593. @1
  594.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  595.             move.l    OneOne,-(SP)        ;
  596.             _InsetRect                    ; inset TempRect
  597.  
  598.             lea        borderShades,a2        ; Get shades for fancy border
  599.             tst.b    wHilited(windowReg)    ; Is window highlighted?
  600.             bnz.s    @drawBorders        ; Yes.  Go draw the borders
  601.             add.w    #$10,a2                ; Use gray shades for inactive windows
  602.             tst.b    threeDWind(a6)        ; Are we using System 7 windows?
  603.             bnz.s    @drawBorders        ; Yes, start drawing
  604.             move.l    GrafGlobals(a5),a0    ; No.  Use dithered gray
  605.             pea        gray(a0)
  606.             _PenPat
  607. @drawBorders
  608.             move.w    (a2)+, -(SP)        ; lower right shade
  609.             move.w    (a2)+, -(SP)        ; upper left shade
  610.             move.w    (a2)+, -(SP)        ; shade for corners
  611.             bsr        DrawShadedRect        ; _FrameRect with shades
  612.  
  613.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  614.             move.l    OneOne,-(SP)        ;
  615.             _InsetRect                    ; inset TempRect
  616.             move.w    (a2)+, D0    ; shade for rect
  617.             bsr        SetupForeColor
  618.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  619.             _FrameRect
  620.  
  621.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  622.             move.l    OneOne,-(SP)        ;
  623.             _InsetRect                    ; inset TempRect
  624.             move.w    (a2)+, -(SP)        ; lower right shade
  625.             move.w    (a2)+, -(SP)        ; upper left shade
  626.             move.w    (a2)+, -(SP)        ; shade for corners
  627.             bsr        DrawShadedRect        ; _FrameRect with shades
  628.  
  629.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  630.             move.l    OneOne,-(SP)        ;
  631.             _InsetRect                    ; inset TempRect
  632.             move.w    (a2)+, D0            ; shade for rect
  633.             bsr        SetupForeColor
  634.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  635.             _FrameRect
  636.  
  637.             move.l    rectReg,-(SP)         ; push the window’s structure rect
  638.             move.l    OneOne,-(SP)        ;
  639.             _InsetRect                    ; inset TempRect
  640.             move.l    #$00030003,-(SP)    ; erase to edge of content rgn
  641.             _PenSize                    ; get a thick pen
  642.             move.l    (A5), A2            ; get graphic globals
  643.             pea     white(A2)            ; white for erasing
  644.             _PenPat                        ; set pen pattern
  645.             move.l    rectReg,-(SP)        ; push TempRect
  646.             _FrameRect                    ; and frame TempRect
  647.             _PenNormal                    ; back to normal pen
  648.  
  649. NotFancy    tst.b    IsProcFive(A6)        ; dBox with a title bar?
  650.             bne.s    DrawTitleBar        ; yes, then draw it
  651.             tst.w    varCodeReg            ; test for dialog windows
  652.             bne     WDefDrawDone        ; yes, dialogs have no title bar
  653.  
  654. ; ------------- draw the title bar -------------
  655. ; Derive the titleBar rect from the structRgn and keep it in TempRect. Keep
  656. ; rectReg preserved since it now points at TempRect.
  657.  
  658. DrawTitleBar
  659.             bsr     BuildTBarRect        ; title rect in TempRect and rectReg
  660.             clr.b    -(SP)                ; room for Boolean
  661.             move.l    rectReg, -(SP)        ; test the title bar rect for
  662.             move.l    (A5), A0            ; quickdraw globals
  663.             move.l    thePort(A0), A0        ; point at current (Wmgr) port
  664.             move.l    visRgn(A0), -(SP)     ; intersection with the visRgn
  665.             _RectInRgn
  666.             tst.b    (SP)+                ; test the result
  667.             bz        WDefDrawDone        ; if not, skip all this work
  668.             tst.b    wHilited(windowReg)        ; do we have a white background?
  669.             bz.s    @inactiveTitle        ; don’t draw shaded title bar
  670.             moveq    #wFrameColor,D0        ; get fore color
  671.             moveq    #wTitleBarShade1, D1    ; get back color
  672.             bra.s    @titleShadeCorrect
  673. @inactiveTitle
  674.             moveq    #wHiliteShadeA,D0    ; Get fore color
  675.             moveq    #wContentColor, D1    ; get back color
  676. @titleShadeCorrect
  677.             bsr        SetupColors            ; set ’em up
  678.             tst.b    isProcFive(A6)        ; dBoxProc with title?
  679.             bnz.s    @1                    ; don’t frame title if so
  680.             move.l    rectReg, -(SP)        ; rect of title bar
  681.             _FrameRect
  682. @1
  683.             move.l    rectReg, -(SP)            ; rect of title bar
  684.             move.l    (SP), -(SP)                ; also for _EraseRect
  685.             move.l    OneOne, -(SP)            ; inset factor of 1, 1
  686.             _InsetRect                        ; exclude the actual frame
  687.             _EraseRect                        ; erase the contents
  688.             tst.b    wHilited(windowReg)        ; do we have a white background?
  689.             bz.s    @doTitle                ; don’t draw 3-d title bar
  690.             moveq    #wLTinge0, D0            ; fore color
  691.             bsr        SetupForeColor            ; do the right thing
  692.             move.w    left(rectReg), -(SP)    ; left of tb interior
  693.             move.w    bottom(rectReg), -(SP)    ; bottom of tb interior
  694.             sub.w    #1, (SP)                ; pen falls to lower right
  695.             _MoveTo
  696.             clr.w    -(SP)                    ; no horiz delta
  697.             move.w    bottom(rectReg), D0        ; vertical delta is bottom-top
  698.             sub.w    top(rectReg), D0
  699.             subq.w    #1, D0
  700.             neg.w    D0                        ; going -v, not +v
  701.             move.w    D0, -(SP)
  702.             _Line                            ; draw left hilite
  703.             move.w    right(rectReg), D0        ; horiz delta is right
  704.             sub.w    left(rectReg), D0        ; minus left
  705.             subq.w    #1, D0
  706.             move.w    D0, -(SP)
  707.             clr.w    -(SP)                    ; no v delta
  708.             _Line                            ; draw top hilite
  709.             moveq    #wLTinge4, D0            ; fore color
  710.             bsr        SetupForeColor            ; do the right thing
  711.             clr.w    -(SP)                    ; no h delta
  712.             move.w    bottom(rectReg), D0        ; vertical delta is bottom-top
  713.             sub.w    top(rectReg), D0
  714.             subq.w    #1, D0
  715.             move.w    D0, -(SP)
  716.             _Line                            ; draw left hilite
  717.             move.w    right(rectReg), D0        ; horiz delta is right
  718.             sub.w    left(rectReg), D0        ; minus left
  719.             subq.w    #1, D0
  720.             neg.w    D0                        ; going -h, not +h
  721.             move.w    D0, -(SP)
  722.             clr.w    -(SP)                    ; no v delta
  723.             _Line                            ; draw top hilite
  724.  
  725. @doTitle
  726. ; ------------- DoTitleString  -------------
  727. ; To prevent title flicker, DoTitleString leaves the left edge of the
  728. ; title in D3 and the right edge in D4.  If the title bar needs to be
  729. ; highlighted, the highlighting is done in 2 sections, one on each side
  730. ; of the title.  DoTitleString draws the title centered in tempRect.
  731.  
  732. ; Warning -- it trashes D3 and D4.
  733.  
  734. ; compute indent factor based on GoAwayButton state
  735.  
  736.             move.w    right(rectReg),D4    ; get right into D4
  737.             move.w    D4,D3                ;
  738.             sub.w    left(rectReg),D3    ; compute width
  739.  
  740.             sub.w    wTitleWidth(windowReg),D3    ; compute extra x
  741.             asr.w    #1,D3                ; divide by 2
  742.  
  743. ; if the string is too long, position left edge
  744.  
  745.             moveq    #2,D0                ; start title at x = 2
  746.             tst.b    wGoAway(windowReg)     ; is there a go away button
  747.             beq.s    @2                    ; skip if there’s not
  748.             moveq    #32,D0                ; start title at x = 32
  749. @2            cmp.w    D0,D3                ; to left of x?
  750.             bge.s    @3                    ; => no, D3 is ok
  751.             move.w    D0,D3
  752. @3
  753.             move.w    D3,D0                ; save left indent in D0                            
  754.             add.w    left(rectReg),D3    ; compute x position
  755.             move.w    D4,-(SP)            ; save right across clip
  756.             tst.b    wZoom(windowReg)    ; zoom flag set?
  757.             beq.s    @4                    ; => no, edge ok
  758.             sub.w    #32,D4                ; get default right edge
  759.             bra.s    @doneAdjustRight    ;                                                    
  760.  
  761. @4                                        ; set clip to d3..d4
  762.             sub.w    D0,D4                ; adjust right to have the same indent as left        
  763. @doneAdjustRight
  764.             move.l     TempRgn(A6),-(SP)    ; get our temp region
  765.             move.l     (SP),-(SP)         ; copy for SectRgn
  766.             _GetClip                    ; and save for restore
  767.  
  768.             move.w    D4,right(rectReg)    ; set right for clipping
  769.             move.l    rectReg,-(SP)        ; push tempRect
  770.             _ClipRect                    ; set clipping to it
  771.  
  772.             move.l    (A5),A0             ; get globals
  773.             move.l    (A0),A0             ; get port
  774.             move.l    clipRgn(A0),-(SP)    ; and the rect region
  775.             move.l    (SP),-(SP)            ; and use clip as dest
  776.             _SectRgn                    ; get the intersection
  777.  
  778.             move.w    (SP)+,right(rectReg); restore tempRect
  779.             move.w    D3,-(SP)            ; push left for MoveTo
  780.  
  781. ; ------------- draw title string -------------
  782.  
  783.             move.w    top(rectReg),D0     ; get top
  784.             add.w    WInfo.wAscent(A6),D0 ; move down to baseline
  785.             addq.w    #1,D0                ; leave 2 pixels white space
  786.             move.w    D0,-(SP)            ; push baseline
  787.             _MoveTo
  788.  
  789.             tst.b    wHilited(windowReg)    ; Is it highlighted?
  790.             beq.s    @noHighlight        ; No
  791.             moveq    #wTextColor,D0        ; get fore color for highlighted title
  792.             bra.s    @drawTitle
  793. @noHighlight
  794.             moveq    #wHiliteShade7,D0    ; Use a gray shade to dim title string if not highlighted. 
  795. @drawTitle
  796.             moveq    #wTitleBarShade1,D1    ; get back color
  797.             bsr        SetupColors            ; set ’em up
  798.             move.w    #srcOr,-(SP)        ; set the mode to source OR
  799.             _TextMode                    ;
  800.  
  801.             move.l    wTitleHandle(windowReg),A0    ; get titleHandle
  802.             _HLock                                ; lock the title down
  803.             move.l    (A0),-(SP)                    ; push title pointer
  804.             _DrawString                         ; draw it
  805.             move.l    wTitleHandle(windowReg),A0    ; get the handle again
  806.             _HUnlock                            ; release it
  807.  
  808.             move.l    TempRgn(A6),-(SP)    ; push the old clip
  809.             _SetClip                    ; and restore it
  810.  
  811. ; ------------- calculate highlite rects  -------------
  812. ; Now calculate the size of the clear area needed for the title
  813. ; (only used if the window is highlighted).  The two registers D3 and
  814. ; D4 are used to supply the left and right edges of the gap in the title
  815. ; area for occupied by the string.  If no title is supplied, then there
  816. ; isn’t a gap.  If there is a title, then there is an extra indentation
  817. ; of a few pixels added.
  818.  
  819.             move.w    D3,D1                ; left in D3, calc right in D1
  820.             add.w    wTitleWidth(windowReg),D1    ; add in the length
  821.  
  822.             cmp.w    D4,D1                ; was title longer than space?
  823.             bge.s    @5                    ; => yes, use D4
  824.             move.w    D1,D4                ;
  825. @5
  826.             tst.w    wTitleWidth(windowReg)    ; is there a title?
  827.             beq.s    @NoIndent            ; no, then don’t include indent
  828.             addq.w    #6,D4                ; indent on right
  829.             subq    #6,D3                ; indent to the left
  830. @NoIndent                                ; no indentation
  831.                                          ; Left in D3, right in D4
  832.  
  833. ; ------------- draw title bar highliting -------------
  834.  
  835.             tst.b    wHilited(windowReg)    ; is it hilited?
  836.             bne.s    DoHilite            ; yes, then draw it
  837.             bra.w     WDefDrawDone                ; no, done with all drawing
  838.  
  839. DoHilite
  840.             moveq    #wHiliteShade8, D0        ; get fore color
  841.             bsr        SetupForeColor            ; set ’em up
  842.  
  843.             move.l    rectReg,-(SP)        ; push the title rect
  844.             move.w    #1,-(SP)            ; push dh
  845.             move.w    WInfo.wBoxDelta(A6),-(SP) ; push dv
  846.             _InsetRect                    ; inset it some
  847.  
  848. ; The dBoxProc with title has a two pixel fancy border around the entire
  849. ; window.  When drawing the highlited pattern, I need to allow for this.
  850.  
  851.             tst.b    IsProcFive(A6)        ; dBoxProc with title?
  852.             beq.s    @NoAdjust            ; no, then skip adjustment
  853.             addq.w    #1,left(rectReg)    ; yes, adjust title bar left
  854.             subq.w    #1,right(rectReg)    ; and right
  855. @NoAdjust
  856.  
  857. ; This WDEF tries to put at least 32 pixels on the left of the title if there is a go-away box.
  858. ; However, if the title bar is less than 32 pixels wide, we will have a problem in which the
  859. ; "racing" stripes will be drawn outside the title bar.
  860. ; The following check is to make sure that the lines will be drawn within the title bar area.
  861.             move.w    right(rectReg),d0    ; get right                                                            
  862.             cmp.w    d0,d3                ; Does lines fit in the title bar?                                    
  863.             ble.s    @linesFitOnRight    ;     yes => continue                                                    
  864.             move.w    d0,d3                ;    no => use the right of rect instead of the calculated value        
  865. @linesFitOnRight                        ;                                                                    
  866.  
  867.             move.w    right(rectReg),-(SP) ; save right of TempRect
  868.             move.w    D3,right(rectReg)    ; new right = title left
  869.  
  870.             move.l    topLeft(rectReg),D0    ; get topLeft
  871.             and.l    #$00070007,D0        ; only use mod 8
  872.             move.l    (A5),A2             ; get globals, save in A2
  873.             move.l    D0,patAlign(A2)     ; set up patAlign
  874.  
  875.             move.l    theZone,curZone(A6)    ; save the current zone 
  876.             move.l    sysZone,theZone        ; going to create the pixpat in sysZone 
  877.             move.l    rectReg,-(SP)        ; fill this rect
  878.             pea     HilitePattern        ; push the pattern address
  879.             _FillRect                    ; fill left half with the pattern
  880.  
  881.             tst.b    wZoom(windowReg)    ; zoom flag set?
  882.             beq.s    @1                    ; => no, use current d4
  883.             move.w    (SP),D0             ; else get right edge of box
  884.             sub.w    #26,D0                ; how much room is there?
  885.             cmp.w    D4,D0                ; need at least 26 pixels
  886.             bge.s    @1                    ; => got ’em, use current d4
  887.             move.w    D0,D4                ; else use right-26
  888.  
  889. @1            move.w    (SP)+,right(rectReg) ; restore right of title box
  890.  
  891. ; This WDEF tries to put at least 26 pixels on the right if there is a zoom box or matches the indent
  892. ; from the left. This may cause a problem in which the "racing stripes" will be drawn outside the title
  893. ; bar area if the title bar is too small. The following check makes sure that the lines will be drawn
  894. ; within the title bar area.
  895.             move.w    left(rectReg),d0    ; get left of rect                                                     
  896.             cmp.w    d0,d4                ; Does lines fit in the title bar?                                     
  897.             bge.s    @linesFitOnLeft        ;    yes => continue                                                     
  898.             move.w    d0,d4                ;    no => use left instead of the calculated value                     
  899. @linesFitOnLeft                            ;                                                                    
  900.  
  901.             move.w    D4,left(rectReg)    ; set new left of title box
  902.             move.l    rectReg,-(SP)        ; fill this rect
  903.             pea     HilitePattern        ; push the pattern address
  904.             _FillRect
  905.  
  906.             move.l    curZone(A6),theZone    ; restore the zone 
  907.             clr.l    patAlign(A2)
  908.  
  909. ; ------------- DoGoAway  -------------
  910.  
  911.             tst.b    wGoAway(windowReg)    ; is there a goaway button?
  912.             beq.s    DoZoom                ; => if not, try for zoom
  913.  
  914.             moveq    #wGoAwayGadget, D0
  915.             bsr        SetupColorPict
  916.             pea        TingeGoAway            ; Address of tinge routine
  917.             bsr         PlotGoAway
  918.  
  919. ; ------------- DoZoom  -------------
  920.  
  921. DoZoom        tst.b    wZoom(windowReg)    ; zoom flag set?
  922.             beq.s    WDefDrawDone        ; no, then done drawing
  923.  
  924.             moveq    #wZoomGadget, D0
  925.             bsr        SetupColorPict
  926.             pea        TingeZoom            ; Address of tinge routine
  927.             bsr         PlotZoom            ; and plot the symbol
  928.             bra.s    WDefDrawDone        ; done drawing
  929.  
  930. ; ------------- goAway and zoom box highliting -------------
  931. ; decide which icon needs hiliting
  932.  
  933. EORStuff    beq.s    EORGoAway            ; => it’s the goAway
  934.             tst.b    wZoom(windowReg)    ; zoom flag set?
  935.             beq.s    WDefDrawDone        ; => no
  936.  
  937.             btst    #HiliteFlagBit, HiliteFlagGlobal
  938.             bz.s    @drawHilitedZoom
  939.             moveq    #wZoomGadget, D0
  940.             pea        TingeZoom
  941.             bra.s    @zoomCommon
  942. @drawHilitedZoom
  943.             moveq    #wZoomHilitedGadget, D0
  944.             clr.l    -(sp)                ; No tinge routine
  945. @zoomCommon
  946.             bsr        SetupColorPict
  947.             bsr         PlotZoom            ; and plot the symbol
  948.             bra.s    WDefDrawDone
  949.  
  950. EORGoAway                                ; hilites/unhilites the goAway
  951.             btst    #HiliteFlagBit, HiliteFlagGlobal
  952.             bz.s    @drawHilitedGoAway
  953.             moveq    #wGoAwayGadget, D0
  954.             pea        TingeGoAway
  955.             bra.s    @goAwayCommon
  956. @drawHilitedGoAway
  957.             moveq    #wGoAwayHilitedGadget, D0
  958.             clr.l    -(sp)                ; Highlighted state needs no tinging
  959. @goAwayCommon
  960.             bsr        SetupColorPict
  961.             bsr        PlotGoAway
  962.  
  963. WDefDrawDone
  964.             move.l    (SP)+, A0            ; return address
  965.             lea        WDefDrawFrame.ParamSize(SP), SP    ; pop params
  966.             jmp        (A0)
  967.  
  968.  
  969. DrawShadedRect
  970.  
  971. ShadedRectFrame    RECORD    0
  972. retAddr        ds.l    1
  973. StartParams    EQU        *
  974. cornerColor    ds.w    1
  975. ulColor        ds.w    1
  976. lrColor        ds.w    1
  977. ParamSize    EQU        *-StartParams
  978.             ENDR
  979.  
  980.             with    ShadedRectFrame
  981.  
  982.             move.w    cornerColor(SP), D0        ; shade/color of corner
  983.             bsr        SetupForeColor            ; make it the pen color
  984.             move.w    left(rectReg), -(SP)    ; start at lower left
  985.             move.w    bottom(rectReg), -(SP)
  986.             subq.w    #1, (SP)
  987.             _MoveTo
  988.             move.l    #$FFFF0000, -(SP)        ; h=0, v=-1
  989.             _Line                            ; draw 1 pixel corner
  990.             move.w    ulColor(SP), D0            ; get shade for left and top
  991.             bsr        SetupForeColor            ; make it the pen color
  992.             move.l    top(rectReg), -(SP)        ; top AND left
  993.             _LineTo                            ; draw line on left side
  994.             move.w    right(rectReg), -(SP)
  995.             subq.w    #1, (SP)
  996.             move.w    top(rectReg), -(SP)
  997.             _LineTo                            ; draw line across top
  998.  
  999.             move.w    cornerColor(SP), D0        ; need corner color again
  1000.             bsr        SetupForeColor            ; make it the pen color
  1001.             move.w    right(rectReg), -(SP)    ; start in upper right
  1002.             subq.w    #1, (SP)
  1003.             move.w    top(rectReg), -(SP)
  1004.             _MoveTo
  1005.             move.l    #$00010000, -(SP)        ; h = 0, v = 1
  1006.             _Line                            ; draw one pixel corner
  1007.             move.w    lrColor(SP), D0            ; get shade for right and bottom
  1008.             bsr        SetupForeColor
  1009.             move.l    bottom(rectReg), -(SP)    ; bottom AND right
  1010.             subq.w    #1, (SP)
  1011.             subq.w    #1, 2(SP)
  1012.             _LineTo                            ; draw line on right
  1013.             move.w    left(rectReg), -(SP)
  1014.             addq.w    #1, (SP)
  1015.             move.w    bottom(rectReg), -(SP)
  1016.             subq.w    #1, (SP)
  1017.             _LineTo                            ; draw line across bottom
  1018.             move.l    (SP)+, A0
  1019.             addq.l    #ShadedRectFrame.ParamSize, SP
  1020.             jmp        (A0)
  1021.  
  1022.             endwith
  1023.  
  1024.             endwith
  1025.  
  1026.  
  1027. ; ================================================
  1028. ; wHit message
  1029. ; ================================================
  1030. ; The hit test is to look for a click in the window’s content region.
  1031. ; The problem with this is that the WDEF extends the window’s contect to
  1032. ; include areas such as the fancy border, title bar, and drop shadow.  If
  1033. ; the user clicks in the fancy border or shadow it is outside of the content
  1034. ; but still within the window.  The reason for the inContent result in the
  1035. ; first place was to let the application know the user clicked any where
  1036. ; within the window excluding the drag area.  So, we check for a click
  1037. ; within the structRgn’s rect but remove the title bar is it has one.
  1038. ; This solved a few problems that hitherto were unknown, or at least not
  1039. ; reported.  ModalDialog no longers reports an error when clicking in the
  1040. ; dBoxProc’s fancy border.  Clicking in the drop shadow is a click in the
  1041. ; window.  Since a dBoxProc with title bar allows switching in MultiFinder,
  1042. ; clicking in the fancy border *must* be considered a click in the window.
  1043.  
  1044. ; paramReg holds the mousePoint in global coordinates .
  1045. ; windowReg holds the window pointer
  1046.  
  1047. HitDoc        clr.w    -(SP)                ; make room for function result
  1048.             move.l    paramReg,-(SP)        ; push the mouse point
  1049.             bsr        StructInTemp        ; structRgn.rgnBBox in TempRect
  1050.             tst.w    varCodeReg            ; dialog window?
  1051.             beq.s     @1                    ; no, they have a title bar
  1052.             tst.b    IsProcFive(A6)        ; dBoxProc with title?
  1053.             beq.s    @2                    ; no, then no title bar
  1054.  
  1055. @1            add.w    titleHgtReg,top(rectReg) ; remove title bar area
  1056. @2            move.l    rectReg,-(SP)        ; point at TempRect
  1057.             _PtInRect                    ; pt in window area less title bar?
  1058.             tst.b    (SP)+                ; well, is it?
  1059.             beq.s    NotInContent        ; if not, go check out drag region
  1060.                                         ; see if its in the grow icon area
  1061.             tst.w    varCodeReg            ; is it a dialogBox?
  1062.             bne.s    JustContent         ; if so, its only in the content
  1063.  
  1064. ; ------------- hit in grow?  -------------
  1065.  
  1066.             tst.b    wHilited(windowReg) ; is it active?                        
  1067.             beq.s    JustContent         ; if not, it cant be in grow
  1068.             move.w    varCode(A6),D0
  1069.             Btst    #hasGrow,D0            ; inGrow enabled?
  1070.             BGT.s    JustContent         ; if not, skip
  1071.  
  1072.             move.l    contRgn(windowReg),A0    ; get region handle                
  1073.             move.l    (A0),A0                 ; get region ptr
  1074.             move.l    rgnBBox+botRight(A0),D0 ; get bottom left of content
  1075.                                         ; first consider the x coordinate
  1076.             moveq    #14,D4                ; keep 14 in a register to save code
  1077.             sub     D4,D0                ; offset x by 14
  1078.             cmp     D0,paramReg            ; if <, just in content
  1079.             BLT.s    JustContent
  1080.  
  1081.             SWAP    D0                    ; its within range on x so try y
  1082.             sub     D4,D0                ; check out y dimension
  1083.             SWAP    paramReg
  1084.             cmp     D0,paramReg            ; compare y coordinates
  1085.             BLT.s    JustContent
  1086.  
  1087.             moveq    #wInGrow,D0         ; flag in grow Icon
  1088.             bra     DoneHitDoc
  1089.  
  1090. ; the point is in the content region so return a ‘1’
  1091.  
  1092. JustContent
  1093.             moveq    #wInContent,D0        ; return in content
  1094.             bra     DoneHitDoc            ; go store function result and return
  1095.  
  1096. ; ------------- hit not in content  -------------
  1097. ; Not in the content.  see if its in the dragRgn (content extended by
  1098. ; titleBar) dBoxProc may have tile higher above content than normal.
  1099.  
  1100. NotInContent
  1101.             bsr     BuildTBarRect        ; title bar rect into rectReg
  1102.             clr.w    -(SP)                ; make room for function result
  1103.             move.l    paramReg,-(SP)        ; push the mouse point
  1104.             move.l    rectReg,-(SP)        ; and push the rect
  1105.             _PtInRect                    ; is the point in the title bar?
  1106.  
  1107.             tst.b    (SP)+                ; examine result
  1108.             beq        DoneHitDoc2            ; if not, return already = 0
  1109.  
  1110.             tst.b    wHilited(windowReg)    ; is it hilited?
  1111.             beq.s    ItsInDrag            ; if not, can’t be in GoAway
  1112.  
  1113. ; ------------- hit in goAway or Zoom?  -------------
  1114. ; test vertical first for goAway and Zoom since they’re the same
  1115.  
  1116.             move.l    paramReg,D0            ; check vertical
  1117.             SWAP    D0                    ; which is high word of mousePoint
  1118.             move.l    windowReg,A0        ; convert pointer if its a pixmap
  1119.             bsr        PortToMap            ; convert                         
  1120.             add.w    bounds+top(A0),D0    ; convert to local
  1121.             sub.w    portRect+top(windowReg),D0     ; compensate for origin
  1122.  
  1123. ; The vertical hit test assumes the zoom is offset from the portRect.
  1124. ; The dBoxProc with title has the title area sharing a portion of the fancy
  1125. ; border surrounding the content.  So, an adjustment is needed to locate
  1126. ; the zoom box’s vertical position.
  1127.  
  1128.             tst.b    IsProcFive(A6)        ; dBoxProc with title bar?
  1129.             beq.s    @OldVert            ; no, use normal vertical test
  1130.             addq.w    #proc5TopAdjust,D0    ; yes, then tweak it
  1131. @OldVert                                ; continue with normal testing
  1132.  
  1133.             add.w    WInfo.wBoxDelta(A6),D0 ; below box?
  1134.             bpl.s    ItsInDrag                ; => yes
  1135.             add.w    #11,D0                    ; in box?
  1136.             BMI.s    ItsInDrag                ; => no
  1137.  
  1138.             tst.b    wGoAway(windowReg)    ; is there a goAway button?
  1139.             beq.s    HitZoom             ; => no, hit-test zoom
  1140.  
  1141.             move.l    paramReg,D0            ; get mousePt
  1142.             ADD     bounds+left(A0),D0    ; convert to local (A0 still valid)  
  1143.             sub     portRect+left(windowReg),D0    ; compensate for origin
  1144.             cmp     #18,D0                ; is it too far right?
  1145.             BGT.s    HitZoom             ; if so, its in drag
  1146.             subq.w    #8,D0                ; it must be at least 7
  1147.             BMI.s    ItsInDrag
  1148.  
  1149.             moveq    #wInGoAway,D0        ; its in the goAway button so signal it
  1150.             bra.s    DoneHitDoc
  1151.  
  1152. HitZoom        tst.b    wZoom(windowReg)    ; zoom flag set?
  1153.             beq.s    ItsInDrag            ; => not in these here parts
  1154.  
  1155.             move.w    paramReg,D0                ; get mousePt
  1156.             move.l    windowReg,A0            ; convert pointer if its a pixmap
  1157.             bsr        PortToMap                ; convert                     
  1158.             add.w    bounds+left(A0),D0    ; convert to local
  1159.             sub.w    portRect+right(windowReg),D0    ; make right edge = 0
  1160.  
  1161. ; The dBoxProc with title has moved the zoom box in towards the left due to
  1162. ; the fancy border.  Need to adjust horizontal hit test for this case.
  1163.  
  1164.             tst.b    IsProcFive(A6)            ; dBoxProc with title?
  1165.             beq.s    @OldZoomHit                ; no, then normal position
  1166.             subq.w    #proc5HitZAdjust,D0        ; tweak it
  1167. @OldZoomHit                                    ; continue with testing
  1168.  
  1169.             cmp.w    #-19,D0                 ; too far left?
  1170.             BLT.s    ItsInDrag                ; => if so, it’s in drag
  1171.             cmp.w    #-9,D0                    ; too far right?
  1172.             BGT.s    ItsInDrag                ; => if so, it’s in drag
  1173.  
  1174.             bsr     IsItSmall                ; is window big?
  1175.             beq.s    @1                        ; => oh boy, right again
  1176.             moveq    #wInZoomOut,D0            ; say window small
  1177.             bra.s    DoneHitDoc                ; und scram-muller
  1178.  
  1179. @1            moveq    #wInZoomIn,D0            ; say window big
  1180.             bra.s    DoneHitDoc                ; and muller out of here
  1181.  
  1182. ItsInDrag    moveq    #wInDrag,D0         ; flag in drag region
  1183.  
  1184. DoneHitDoc    move.l    D0,ProcResult(A6)        ; update function result
  1185. DoneHitDoc2    rts
  1186.  
  1187.  
  1188. ; ================================================
  1189. ; wCalcRgns message
  1190. ; ================================================
  1191. ; CalcDoc  -- calculate the structure and content regions for the window pointed
  1192. ; to by windowReg.  First update size for zooming if necessary
  1193.  
  1194. CalcDoc     tst.b    wZoom(windowReg)    ; zoom flag set?
  1195.             beq.s    @1                    ; => no
  1196.             bsr     IsItSmall            ; update window size
  1197.  
  1198. ; ------------- calc ContRgn -------------
  1199. @1
  1200.             bsr        GetRect                ; make a rectangular content region
  1201.             move.l    contRgn(windowReg),-(SP) ; content region gets result
  1202.             move.l    rectReg,-(SP)        ; tempRect is the rectangle
  1203.             _RectRgn                    ; go make the region into content region
  1204.  
  1205. ; ------------- calc structRgn -------------
  1206. ; now do the structure region.    First correct the bounding rectangle (tempRect) for
  1207. ; structure instead of content
  1208.  
  1209.             move.l    #$00020002,D4        ; get the shadow factor for DBox
  1210.             move.l    structRgn(windowReg),-(SP) ; push the structRgn for later
  1211.             move.l    rectReg,-(SP)        ; tempRect is the rect in rectReg
  1212.             move.l    rectReg,-(SP)        ; make two copies
  1213.             move.l    MinusOne,-(SP)        ; make 1 pixel bigger, all around
  1214.             _InsetRect                    ; make it bigger
  1215.  
  1216.             tst.w    varCodeReg            ; is it dBox?
  1217.             bne.s    DoDBoxCalc            ; skip if it is
  1218.  
  1219.             move.w    titleHgtReg,D0         ; move up to top of window
  1220.             subq.w    #1,D0                ; tweak it
  1221.             sub.w    D0,top(rectReg)     ; and set top of struct region
  1222.             LSR.l    #1,D4                ; adjust shadow factor
  1223.             bra.s    CalcCommon            ; use common code for the rest
  1224.  
  1225. ; ------------- calc structRgn for dialogs -------------
  1226. DoDBoxCalc
  1227.             cmp     #1,varCodeReg        ; is it variant 1?
  1228.             bne.s    CalcCommon
  1229.  
  1230.             move.l    rectReg,-(SP)        ; tempRect is the rect in rectReg
  1231.             move.l    #$FFF9FFF9,-(SP)    ; push (-7,-7)
  1232.             _InsetRect                    ; inset it
  1233.  
  1234. ; The dBoxProc with title needs a larger structRgn. Also, a portion of this
  1235. ; title area is shared with the fancy border that surrounds the    content.
  1236.  
  1237.             tst.b    IsProcFive(A6)        ; dBoxProc with title?
  1238.             beq.s    CalcCommon            ; skip if without title bar
  1239.             move.w    titleHgtReg,D0         ; move up to top of window
  1240.             subq.w    #proc5TopAdjust,D0    ; tweak it
  1241.             sub.w    D0,top(rectReg)     ; and set top of struct region
  1242.  
  1243. CalcCommon                                ; create the structRgn for all windows.
  1244.             _RectRgn                    ; RectRgn(structRgn,tempRect)
  1245.             tst     varCodeReg
  1246.             beq.s    @1                    ; if so, it has shadow
  1247.             cmp     #3,varCodeReg        ; is it variant 3?
  1248.             bne.s    CalcDone            ; if not, no shadow
  1249. @1
  1250.  
  1251. ; ------------- include drop shadow -------------
  1252. ; now add in the 1 or 2 pixel drop shadow
  1253.  
  1254.             move.l    TempRgn(A6),-(SP)    ; get temp region
  1255.             move.l    rectReg,-(SP)        ; tempRect is the rect in rectReg
  1256.             move.l    (SP),-(SP)            ; save another copy
  1257.             move.l    D4,-(SP)            ; push shadow factor
  1258.             _OffsetRect                 ; offset it
  1259.             _RectRgn
  1260.  
  1261.             move.l    structRgn(windowReg),-(SP)    ;
  1262.             move.l    TempRgn(A6),-(SP)            ; get temp region
  1263.             move.l    structRgn(windowReg),-(SP)    ; structure gets the result
  1264.             _UnionRgn                            ; add it in
  1265.  
  1266. CalcDone    rts                            ; all done with CalcDocRgns
  1267.  
  1268.  
  1269. ; ================================================
  1270. ; wGrow message
  1271. ; ================================================
  1272. ; GrowDoc handles the grow message by drawing a grow outline based on
  1273. ; the rectangle held in paramReg.  First make it one pixel bigger to
  1274. ; jibe with the structure then frame the entire window.
  1275.  
  1276. GrowDoc        move.l    paramReg,-(SP)        ; push the rect
  1277.             move.l    MinusOne,-(SP)        ; push (-1,-1)
  1278.             _InsetRect
  1279.             move.l    paramReg,A3            ; get rect ptr
  1280.             move.l    topLeft(A3),-(SP)    ; save topleft for below
  1281.             move.w    titleHgtReg,D0         ; adjust for title
  1282.             subq.w    #1,D0                ; and tweak it
  1283.             sub.w    D0,top(A3)            ; and save it
  1284.             move.l    paramReg,-(SP)        ; push the rectangle
  1285.             _FrameRect                    ; frame it
  1286.  
  1287. ; ------------- draw the lower horizontal -------------
  1288. ; line at the top of the horizontal scroll bar area
  1289.  
  1290.             move.w    left(A3),-(SP)        ; push left
  1291.             move.w    bottom(A3),-(SP)    ; push bottom
  1292.             sub     #scrollBarSize,(SP)    ; a few pixels above bottom
  1293.             move.l    (SP),-(SP)            ; make a copy of this point
  1294.             _MoveTo                     ; move to it
  1295.             move.w    right(A3),2(SP)     ; now go to the right edge
  1296.             _LineTo                     ; draw the horizontal line
  1297.  
  1298. ; ------------- draw the upper horizontal -------------
  1299. ; line below the title bar area
  1300.  
  1301.             move.l    (SP),topLeft(A3)    ; restore topLeft, leave on stack
  1302.             move.l    (SP),-(SP)            ; make a copy of this point
  1303.             _MoveTo                     ; move to it
  1304.             move.w    right(A3),2(SP)     ; now go to the right edge
  1305.             _LineTo                     ; draw the horizontal line
  1306.  
  1307. ; ------------- draw the vertical line -------------
  1308. ; line along left edge of the vertical scroll bar
  1309.  
  1310.             move.w    right(A3),-(SP)     ; push right
  1311.             sub     #scrollBarSize,(SP)    ; few pixels to the left
  1312.             move.w    top(A3),-(SP)        ; push top
  1313.             move.l    (SP),-(SP)            ; make a copy of this point
  1314.             _MoveTo                     ; and move to it
  1315.             move.w    bottom(A3),(SP)     ; now go to bottom edge
  1316.             _LineTo                     ; draw the vertical line
  1317.                                         ; restore the rect back to
  1318.                                         ; how it was when we got it
  1319.             move.l    paramReg,-(SP)        ; push the rect
  1320.             move.l    OneOne,-(SP)        ; push (1,1)
  1321.             _InsetRect
  1322. GrowDone    rts
  1323.  
  1324.  
  1325. ; ================================================
  1326. ; wDrawGIcon message
  1327. ; ================================================
  1328. ;  Draw the grow icon.    First make this window the current grafPort
  1329.  
  1330. DrawGIcon
  1331.             move.l    GrafGlobals(A5),A0    ; get the current port and save it  
  1332.             move.l    thePort(A0),-(SP)    ;                                    
  1333.             move.l    windowReg,-(SP)        ; push the window’s port
  1334.             _SetPort                    ; make that the port
  1335.             clr.l    globalOffset(a6)    ; No offset for BW systems.
  1336.             tst.b    IsColor(A6)            ; is this a color system?
  1337.             beq        @NoColor8            ; Nope.  Skip color stuff                                                
  1338.  
  1339. ; ------------- do color window -------------
  1340. ; The region passed to _DeviceLoop has to be offset into global coordinates on
  1341. ; color systems since we’re drawing into the window manager port.
  1342.  
  1343.             move.l    GrafGlobals(a5),a0    ; get the port                                                             
  1344.             move.l    thePort(a0),a0        ;                                                                        / /
  1345.             lea        portBits(a0),a0        ; point to “bitmap” in the port                                            / /
  1346.             tst.w    rowBytes(a0)        ; is this a color port?                                                     
  1347.             bpl.s    @bitmap                ;                                                                         
  1348.             move.l    baseAddr(a0),a0        ; pixmap handle                                                             
  1349.             move.l    (a0),a0                ; pixmap ptr                                                             
  1350. @bitmap                                    ;                                                                         
  1351.             move.l    ScrnBase,d0            ; get base address of screen                                             
  1352.             cmp.l    baseAddr(a0),d0        ; is it the same as thePort’s ?                                             
  1353.             beq.s    @drawToScreen        ; yes => we are drawing to screen                                         
  1354.             move.w    #1, -(SP)            ; no => assume old-port, depth equals 1                                     
  1355.             tst.w    rowBytes(A0)        ; is this an old-style port?                                             
  1356.             bpl.s    @depthOk            ; yes. depth of 1 on stack is okay                                         
  1357.             move.w    pmPixelSize(A0),(SP)    ; fix depth on stack                                                 
  1358. @depthOk                                ;                                                                         
  1359.             move.w    #fakeDeviceFlags, -(SP)    ; assume non-CQD case                                                 
  1360.             clr.l    -(SP)                ; NIL gDeviceHandle for non-CQD machines                                 
  1361.             btst    #6,ROM85            ; Color QuickDraw available?                                             
  1362.             bnz        @deviceAndFlagsOk    ; of not, fake versions on stack are correct                             
  1363.             move.l    theGDevice, A1        ; current device GDHandle                                                 
  1364.             move.l    A1,(SP)                ; fix gdHandle on stack                                                     
  1365.             move.l    (A1), A1            ; point to the device                                                     
  1366.             move.w    gdFlags(A1),4(SP)    ; fix gdFlags on stack                                                     
  1367. @deviceAndFlagsOk                        ;                                                                         
  1368.             clr.l    -(SP)                ; flag clear (not drawing to screen)                                     
  1369.             bsr        WDefDrawGIcon        ;                                                                          
  1370.             bra        @exitDrawGIcon        ;                                                                          
  1371. @drawToScreen                            ;                                                                         
  1372.             lea        globalOffset(a6),a2
  1373.             move.l    portRect(windowReg),d4
  1374.             move.l    d4,(a2)
  1375.  
  1376.             move.l    a2,-(sp)
  1377.             _LocalToGlobal                ; Convert topLeft to global coordinates
  1378.             move.l    d4,-(SP)            ; push src point                     
  1379.             move.l    a2,-(SP)            ; push ptr to dest point             
  1380.             _SubPt                        ; get local to global offset         
  1381.  
  1382. ; save the foreground and background of the WMgr port & set new colors
  1383.  
  1384.             subq    #6,SP                ; make room for rgbColor on stack     
  1385.             move.l    SP,-(SP)            ; push pointer to placeholder         
  1386.             _GetForeColor                ; get the window port’s foreColor     
  1387.             subq    #6,SP                ; make room for the backColor too     
  1388.             move.l    SP,-(SP)            ; push pointer to placeholder         
  1389.             _GetBackColor                ; get the window port’s backColor     
  1390.  
  1391. ; Get the intersection of the clipRgn and visRgn of the window to use as the
  1392. ; clipping region for drawing the grow icon.
  1393.  
  1394.             move.l    clipRgn(windowReg),-(sp)
  1395.             move.l    visRgn(windowReg),-(sp)
  1396.             move.l    tempRgn(a6),-(sp)
  1397.             _SectRgn                     ; Get intersection of portRect & visRgn
  1398.  
  1399.             move.l    tempRgn(a6),-(sp)
  1400.             move.l    (a2),-(sp)
  1401.             _OfsetRgn                    ; Move the clipRgn into global coordinates
  1402.  
  1403.             move.l    WMgrCPort,-(sp)
  1404.             _SetPort                    ; Set port back to WMgrPort
  1405.  
  1406.             subq    #4,sp                ;                                                 
  1407.             _NewRgn                        ; Allocate new region…                             
  1408.             move.l    (sp),-(sp)            ;                                                 
  1409.             _GetClip                    ;  to save WMgrPort’s clipRgn in.                 
  1410.  
  1411.             move.l    tempRgn(A6),-(sp)
  1412.             move.l    (SP), -(SP)            ; once more for DeviceLoop
  1413.             _SetClip                    ; Clip to the window’s clipRgn
  1414.             bra.s    @isColor            ; Fill in the other _DeviceLoop parameters
  1415.  
  1416. @NoColor8                                ; END OF COLOR-ONLY SECTION
  1417.             move.l    tempRgn(A6), -(SP)    ; rgn handle
  1418.             move.l    (SP), -(SP)            ; once more for DeviceLoop
  1419.             pea        portRect(windowReg)    ; local coord rect
  1420.             _RectRgn
  1421. @isColor
  1422.             pea        WDefDrawGIcon        ; address of devloop drawing proc
  1423.             clr.l    -(SP)                ; no unusual activities
  1424.             clr.l    -(SP)                ; and no user data
  1425.             _DeviceLoop
  1426.             tst.b    IsColor(A6)            ; is it a color system?
  1427.             beq.s    @exitDrawGIcon        ; no, so skip this restore
  1428.  
  1429.             move.l    (sp),-(sp)
  1430.             _SetClip                    ; Restore WMgrPort clipRgn
  1431.             _DisposRgn                    ; Get rid of saved region
  1432.  
  1433.             move.l    SP,-(SP)            ; push ptr to rgbColor previously saved on top of stack      
  1434.             _RGBBackColor                ;                                  
  1435.             addq    #6,SP                ; trash backcolor                 
  1436.             move.l    SP,-(SP)            ;                                  
  1437.             _RGBForeColor                ;                                 
  1438.             addq    #6,SP                ;                                 
  1439. @exitDrawGIcon
  1440.             _SetPort                    ; restore the incoming port (saved above)  
  1441.             rts
  1442.  
  1443. WDefDrawGIcon
  1444.             with    WDefDrawFrame
  1445.  
  1446.             move.w    depth(SP), curDepth(A6)    ; save this for SetupColor magic
  1447.             move.l    devHandle(SP), D1        ; pass this drawing device
  1448.             bsr        CheckAvailableColors
  1449.  
  1450.             moveq    #wFrameColor,D0        ; get fore color
  1451.             moveq    #wContentColor,D1    ; get back color
  1452.             bsr        SetupColors            ; set ’em up
  1453.  
  1454. ; ------------- plot grow icon -------------
  1455. ; compute the grow icon rectangle in tempRect which is inside the lower
  1456. ; left corner of the scroll bar area.
  1457.  
  1458.             move.l    globalOffset(a6),d4                        ; Get offset amount
  1459.             move.l    portRect+botRight(windowReg),(rectReg)    ; botRight=topLeft
  1460.             move.l    (rectReg),botRight(rectReg)                ; copy into botRight, too
  1461.             add.l    d4,(rectReg)                            ; Adjust for global case
  1462.             add.l    d4,botRight(rectReg)                    ; Adjust for global case
  1463.             sub.w    #scrollBarSize-2,top(rectReg)            ; remove scroll area
  1464.             sub.w    #scrollBarSize-2,left(rectReg)
  1465.  
  1466.             tst.b    wHilited(windowReg)    ; is it hilited?
  1467.             bne.s    @1                    ; yes, plot it
  1468.             move.l    rectReg,-(SP)         ; TempRect still in rectReg
  1469.             _EraseRect                    ;
  1470.             subi.l    #$00010001,(rectReg)    ; Move topLeft back out
  1471.             bra.s    PlotBoundary        ;
  1472. @1                                        ;
  1473.             moveq    #wGrowGadget, D0
  1474.             bsr        SetupColorPict        ; Get the grow gadget
  1475.             beq.s    @2                    ; Don’t to extra stuff for black and white gadget
  1476.  
  1477. ; On color systems, the grow gadget is on a gray background;  do the gray.
  1478.  
  1479.             move.w    d2,-(sp)            ; PlotSymbol will need D2, so save it in case _EraseRect trashes it
  1480.             moveq    #wTitleBarShade1, D0    ; Use title bar gray for gray of grow icon
  1481.             bsr        SetupBackColor
  1482.             move.l    rectReg, -(SP)
  1483.             _EraseRect                    ; Gray shade
  1484.             move.w    (sp)+,d2
  1485.  
  1486. ; The inside of the grow gadget it a darker gray.  Set the rectangle to the area
  1487. ; to darken
  1488.  
  1489.             move.l    #$00030003,d3            ; Save ourselves 6 bytes by using a register
  1490.             move.l    #$00040004,d4
  1491.             add.l    d4,(rectReg)
  1492.             sub.l    d3,botRight(rectReg)
  1493. @2
  1494.             subi.l    #$00010001,(rectReg)    ; We subtracted one pixel less to avoid some flickering,
  1495.             pea        TingeGrow            ; Tinging routine for grow gadget
  1496.             bsr        PlotSymbol            ; so we have to put those pixels back before
  1497.  
  1498. ; Set colors for plotting boundary
  1499.  
  1500.             moveq    #wFrameColor, D0    ; get fore color
  1501.             moveq    #wContentColor,D1    ; get back color
  1502.             bsr        SetupColors            ; set it up
  1503.  
  1504. ; ------------- plot the boundary lines -------------
  1505. ; plot the left edge of the vertical scroll bar area and the top edge
  1506. ; of the horizontal scroll bar area.
  1507.  
  1508. PlotBoundary
  1509.             move.w    portRect+left(windowReg),-(SP)    ; push portRect.left
  1510.             move.l    globalOffset(a6),d4
  1511.             add.w    d4,(sp)                            ; Adjust for global case
  1512.             move.w    top(rectReg),-(SP)                ; push tempRect.top
  1513.             _MoveTo
  1514.             move.w    portRect+right(windowReg),-(SP)    ; push portRect.right
  1515.             add.w    d4,(sp)                            ; Adjust for global case
  1516.             move.w    top(rectReg),-(SP)                ; push tempRect.top
  1517.             _LineTo                                    ; draw the horizontal line
  1518.  
  1519.             swap    d4                                ; Get vertical offset into low word
  1520.             move.w    left(rectReg),-(SP)                ; push tempRect.left
  1521.             move.w    (SP),-(SP)                        ; copy it again for later
  1522.             move.w    portRect+top(windowReg),-(SP)    ; push portRect.top
  1523.             add.w    d4,(sp)                            ; Adjust for global case
  1524.             _MoveTo                                 ; move to it
  1525.             move.w    portRect+bottom(windowReg),-(SP) ; push portRect.bottom
  1526.             add.w    d4,(sp)                            ; Adjust for global case
  1527.             _LineTo                                 ; draw the vertical line
  1528.  
  1529. ; ------------- done with grow drawing -------------
  1530. ; don’t forget to take care of colors saved on stack
  1531.  
  1532. DrawGrowDone
  1533.             move.l    (SP)+, A0            ; return address
  1534.             lea        WDefDrawFrame.ParamSize(SP), SP    ; pop params
  1535.             jmp        (A0)
  1536.  
  1537.             endwith
  1538.  
  1539.  
  1540. ; ================================================
  1541. ; Plotters
  1542. ; ================================================
  1543. ; common code to draw little things like the goAway, zoom, and grow boxes
  1544.  
  1545. ; A1 holds the symbol
  1546. ; rectReg is the rectangle’s address
  1547. ; D2 the plotting mode
  1548. ; A2 points at bitmap or pixmap rect info
  1549.  
  1550. ; ------------- Apply color tinge to the zoom box -------------
  1551.  
  1552. TingeZoom
  1553.             move.l    #$00040004,d3
  1554.             sub.l    d3,botRight(rectReg)
  1555.             move.l    rectReg,-(sp)
  1556.             _FrameRect                    ; Draw little box in zoom box first
  1557.             add.l    d3,botRight(rectReg)    ; Restore full rectangle
  1558.  
  1559. ; ------------- Apply color tinge to the goAway box -------------
  1560.  
  1561. TingeGoAway
  1562.             move.l    rectReg,-(sp)
  1563.             _FrameRect                    ; Draw upper part of shade
  1564.  
  1565.             move.l    OneOne,d3
  1566.             sub.l    d3,botRight(rectReg)
  1567.             move.l    rectReg,-(sp)
  1568.             _FrameRect                    ; Draw lower shade
  1569.  
  1570.             move.l    rectReg,-(sp)
  1571.             move.l    d3,-(sp)
  1572.             _OffsetRect                    ; Position rectangle for light shade
  1573.  
  1574.             moveq    #wLTinge0, D0
  1575.             bsr        SetupForeColor        ; Do light tinge
  1576.  
  1577.             move.l    rectReg,-(sp)
  1578.             _FrameRect                    ; Draw light tinge
  1579.             sub.l    d3,(rectReg)        ; Restore rectangle
  1580.             rts
  1581.  
  1582. ; ------------- Apply color tinge to the grow box -------------
  1583.  
  1584. TingeGrow
  1585.             movem.l    d3/d4,-(sp)            ; Save these registers
  1586.             move.l    #$00010001,d4
  1587.             add.l    d4,botRight(rectReg)
  1588.             bsr.s    DrawGrowBoxPart        ; Draw a section of the grow icon
  1589.  
  1590.             moveq    #wDTingeF, D0        ; Reset tinge for smaller box
  1591.             bsr        SetupForeColor
  1592.  
  1593.             move.l    rectReg,-(sp)
  1594.             move.l    #-1,-(sp)            ; Move rectangle up and to the left
  1595.             _OffsetRect                    ; Set up position of smaller box
  1596.             sub.l    #$00030003,botRight(rectReg)
  1597.             bsr.s    DrawGrowBoxPart        ; Draw smaller box
  1598.  
  1599.             move.l    rectReg,-(sp)
  1600.             move.l    d4,-(sp)
  1601.             _InsetRect
  1602.             add.l    d4,(rectReg)
  1603.             moveq    #wTitleBarShade4,d0
  1604.             bsr        SetupBackColor
  1605.             move.l    rectReg,-(sp)
  1606.             _EraseRect                    ; Refresh the dark gray inside small box
  1607.  
  1608.             sub.l    d4,(rectReg)
  1609.             asl.l    #2,d4
  1610.             add.l    d4,botRight(rectReg)    ; Restore rectangle
  1611.             movem.l    (sp)+,d3/d4            ; Restore registers
  1612.  
  1613. ; The main body of the wDrawGIcon routine shifted the rectangle.  Shift it back
  1614. ; to its original position here to save a check back in the mainstream.
  1615.  
  1616.             sub.l    d4,(rectReg)
  1617.             add.l    d3,botRight(rectReg)
  1618.  
  1619.             rts
  1620.  
  1621. ; The grow box is made of two boxes that look like this:
  1622. ;
  1623. ;    @@@@@
  1624. ;    @oooo    DrawGrowBoxPart will draw this part based on the rectangle
  1625. ;    @o**@    in rectReg.  If we REALLY want to save some code, call TingeGoAway
  1626. ;    @o**@    instead of DrawGrowBoxPart.  The resulting gadget looks a little
  1627. ;    @o@@@    strange, but it’s passable in a pinch.
  1628. ;
  1629.  
  1630. DrawGrowBoxPart
  1631.             move.l    rectReg,-(sp)
  1632.             _FrameRect                    ; Draw dark frame
  1633.             moveq    #wLTinge0,D0
  1634.             bsr        SetupForeColor
  1635.  
  1636.             move.l    (rectReg),d3        ; Get topLeft
  1637.             add.l    OneOne,d3
  1638.  
  1639.             move.w    d3,-(sp)
  1640.             move.w    bottom(rectReg),-(sp)
  1641.             sub.w    #1,(sp)
  1642.             _MoveTo
  1643.             move.l    d3,-(sp)
  1644.             _LineTo                        ; Draw one light line
  1645.             move.w    right(rectReg),-(sp)
  1646.             sub.w    #1,(sp)
  1647.             swap    d3
  1648.             move.w    d3,-(sp)
  1649.             _LineTo
  1650.             rts
  1651.  
  1652. ; ------------- plot the goAway box  -------------
  1653.  
  1654. PlotGoAway
  1655.             bsr        BuildTBarRect        ; build a title bar rect in rectReg
  1656.             moveq    #9,D1                ; add margin to left
  1657.             bra.s    PlotIt                ; use common code to plot it
  1658.  
  1659. ; ------------- plot the zoom box  -------------
  1660.  
  1661. PlotZoom
  1662.             bsr        BuildTBarRect        ; build a title bar rect in rectReg
  1663.             move    right(rectReg),left(rectReg) ; left := right-22
  1664.             moveq    #-20,D1             ;
  1665.  
  1666. ; The dBoxProc with title has a fancy border around it’s structure.
  1667. ; This has to be taken into consideration when plotting the zoom box.
  1668.  
  1669.             tst.b    IsProcFive(A6)        ; dBoxProc with title?
  1670.             beq.s    @1                    ; skip if standard title bar
  1671.             subq.w    #1,D1                ; inset zoom to the left
  1672. @1                                        ; don’t tweak it
  1673.  
  1674. ; ------------- plot the little dude face  -------------
  1675. ; make Temprect into a 16x16 square for our little bitmap
  1676. ; dest rect top = rectReg.top + WInfo.wBoxDelta - 1
  1677. ; dest rect bot = dest rect top + (A2).bottom - (A2).top
  1678. ; dest rect left = rectReg.left + D1
  1679. ; dest rect right = dest rect left + (A2).right - (A2).left
  1680.  
  1681. PlotIt
  1682.             move.w    d2,-(sp)
  1683.             add.w    D1,left(rectReg)     ; add offset to left
  1684.             move.w    WInfo.wBoxDelta(A6), D1
  1685.             add.w    D1, top(rectReg)     ; add offset to top
  1686.             addq.w    #1, top(rectReg)     ; align bitmap
  1687.  
  1688.             move.l    topLeft(rectReg),botRight(rectReg) ; topLeft = botRight
  1689.  
  1690.             move.w    2+bottom(A2), D0
  1691.             sub.w    2+top(A2), D0
  1692.             add.w    D0, bottom(rectReg);
  1693.  
  1694.             move.w    2+right(A2), D0
  1695.             sub.w    2+left(A2), D0
  1696.             add.w    D0, right(rectReg);
  1697.  
  1698.             move.l    rectReg, -(SP)
  1699.             move.l    #$FFFFFFFF, -(SP)
  1700.             _InsetRect
  1701.             moveq    #wTitleBarShade1, D0
  1702.             bsr        SetupBackColor
  1703.             move.l    rectReg, -(SP)
  1704.             _EraseRect
  1705.             move.l    rectReg, -(SP)
  1706.             move.l    OneOne, -(SP)
  1707.             _InsetRect
  1708.             move.w    (sp)+,d2
  1709.  
  1710. ; ------------- plot the little dude’s face  -------------
  1711. ; PlotSymbol -- A2 contains a PicHandle. rectReg holds the address of
  1712. ; the destination rectangle.
  1713.  
  1714. ; D2 is non-zero for pixmap, zero for bitmap
  1715. ; pixmap is not included in this example since the format and kind of
  1716. ; these resources is subject to change and private
  1717. ; A2 points to bounds/rect/bits
  1718. ; rectReg holds destination rect
  1719.  
  1720. PlotSymbol
  1721.             move.w    D2,-(sp)            ; Save color/BW flag
  1722.             tst.b    D2                    ; use picture or bits?
  1723.             bz.s    PlotBW                ; if zero, use CopyBits
  1724.             tst.b    gadgetHighlight(a6)
  1725.             bz.s    @notHighlighted
  1726.             moveq    #wTitleBarDark, D0
  1727.             moveq    #wTingeLight, D1
  1728.             bra.s    plotSetupCommon
  1729. @notHighlighted
  1730.             moveq    #wTitleBarLight, D0
  1731.             moveq    #wTitleBarDark, D1
  1732. plotSetupCommon
  1733.             bsr        SetupColors
  1734.             move.l    workPixmap(A6), A0
  1735.             move.l    (A0), A0
  1736.             move.l    A0, -(SP)
  1737.             bra.s    copyBitsPixCommon
  1738.  
  1739. PlotBW
  1740.             lea     IconBitmap,A0        ; get pointer to source bitmap
  1741.             move.w    (A2)+, rowBytes(A0)
  1742.             move.l    (A2)+, bounds(A0)
  1743.             move.l    (A2)+, bounds+4(A0)
  1744.             move.l    A2, baseAddr(A0)
  1745.  
  1746.             pea     IconBitmap            ; push pointer source bitmap
  1747. copyBitsPixCommon
  1748.             move.l    (SP),A0             ; remember in A0, too
  1749.             move.l    GrafGlobals(A5),A1    ; get lisaGraf global baseaddress
  1750.             move.l    thePort(A1),A1        ; get thePort
  1751.             pea     portBits(A1)        ; that’s the destination bitmap
  1752.             pea     bounds(A0)            ; boundsRect of bitmap is source
  1753.             move.l    rectReg,-(SP)        ; tempRect is the destination
  1754.             clr.w    -(SP)
  1755.             clr.l    -(SP)                ; no mask region
  1756.                                         ; the colors should be OK here
  1757.                                         ; transfer the bitMap (stretching as necessary...)
  1758.             _CopyBits                    ; stretch those bits
  1759.             move.l    tempPixels(A6), A0    ; get the locked pixels (if any)
  1760.             _HUnlock                    ; and unlock them
  1761.  
  1762.             move.w    (sp)+,D2
  1763.             bz.s    @noTingeRoutine        ; Don’t tinge for black & white case
  1764.  
  1765. ; All the tinge routines do the dark tinge first, so set it up for them
  1766.  
  1767.             moveq    #wDTingeF, D0
  1768.             bsr        SetupForeColor
  1769.  
  1770.             move.l    4(sp),d0            ; Get address of tinging routine
  1771.             bz.s    @noTingeRoutine        ; No; get out of here.
  1772.             move.l    (sp)+,(sp)            ; Push down return address
  1773.             move.l    d0,a0
  1774.             jmp        (a0)                ; Tinge the gadget
  1775. @noTingeRoutine
  1776.             move.l    (sp)+,a0            ; Get return address
  1777.             addq    #4,sp                ; Remove tinge routine from stack
  1778.             jmp        (a0)                ; Return to caller
  1779.  
  1780. ; ================================================
  1781. BuildTBarRect
  1782. ; ================================================
  1783. ; BuildTBarRect builds a rectangle enclosing the titleBar in TempRect
  1784. ; leave rectReg pointing at TempRect, which is nice.
  1785.  
  1786. ; WARNING -- Trashes D0,A0,A1,rectReg
  1787.  
  1788.             bsr.s    StructInTemp        ; structRgn.rgnBBox in rectReg
  1789.                                         ; make bottom := top + WHeight
  1790.             move    top(rectReg),D0        ; get top
  1791.             add.w    titleHgtReg,D0         ; add precomputed height
  1792.             move    D0,bottom(rectReg)    ; update bottom
  1793.  
  1794. ; The dBoxProc with title has no shadow, don’t subtract off right edge.
  1795.             tst.b    IsProcFive(A6)        ; dBoxProc with title?
  1796.             bne.s    @NoInset            ; no, then standard title bar
  1797.  
  1798.             subq    #1,right(rectReg)    ; inset right
  1799. @NoInset                                ; needed another entry point
  1800.             rts                         ; return to caller
  1801.  
  1802.  
  1803. ; ================================================
  1804. StructInTemp
  1805. ; ================================================
  1806. ; Get structRgn.rgnBBox into TempRect and keep TempRect address in rectReg
  1807.  
  1808. ; WARNING - trashes A0
  1809.  
  1810.             move.l    structRgn(windowReg),A0    ; get region handle
  1811.             move.l    (A0),A0                 ; get region ptr
  1812.             addq    #rgnBBox,A0             ; point A0 at the bounding box
  1813.             move.l    (A0)+,(rectReg)            ; copy rgnBox to TempRect
  1814.             move.l    (A0)+,botRight(rectReg)    ;
  1815.             rts
  1816.  
  1817.  
  1818. ; ================================================
  1819. IsItSmall
  1820. ; ================================================
  1821. ; IsItSmall returns NE if the window has been resized or moved (NE if window "small")
  1822. ; It updates smallsize if it has.  (If tab, only move small window).
  1823.  
  1824. ; WARNING -- Trashes A0,A2 and TempRect
  1825.  
  1826.             bsr.s    GetRect             ; rectReg = curSize
  1827.             move.l    wDataHandle(windowReg),A0    ; get data handle
  1828.             move.l    (A0),A2             ; A2 = bigSize
  1829.             addq    #8,A2
  1830.                                         ; the window is large if all corners
  1831.                                         ; are within 7 of their default positions
  1832.             bsr.s    ChkPoint            ; compare topleft
  1833.             bne.s    IsSmall             ; => not close enough
  1834.             bsr.s    ChkPoint            ; compare botRight
  1835.             beq.s    NotSmall            ; => it’s close enough
  1836.  
  1837. IsSmall     move.l    wDataHandle(windowReg),A0    ; get data handle
  1838.             move.l    (A0),rectReg         ; save window’s current size
  1839.             bsr.s    GetRect             ; get current size into rectReg
  1840.             moveq    #1,D0                ; return NE!
  1841. NotSmall    lea     TempRect,rectReg    ; restore rectReg
  1842.             rts                            ; we’re done
  1843.  
  1844.  
  1845. ; ================================================
  1846. ChkPoint
  1847. ; ================================================
  1848. ; This routine is called in sequence.  First time it checks topLeft,
  1849. ; the next time is will check botRight.  It compares the rect in
  1850. ; TempRect against the rect pointed at in A2.
  1851.  
  1852. ; WARNING - increments rectReg
  1853.  
  1854.             move.l    (A2),-(SP)            ; make point into a rect
  1855.             move.l    (A2)+,-(SP)         ; by pushing twice
  1856.             move.l    SP,-(SP)            ; and insetting by 7
  1857.             move.l    #$FFF9FFF9,-(SP)    ;
  1858.             _InsetRect                    ;
  1859.             clr.w    -(SP)                ; is cursize within 7 of
  1860.             move.l    (rectReg)+,-(SP)     ; that point?
  1861.             pea     6(SP)                ;
  1862.             _PtInRect                    ;
  1863.             subq.b    #1,(SP)             ; reverse sign of result
  1864.             move.b    (SP)+,D0            ;
  1865.             addq    #8,SP                ; strip off the rect
  1866.             rts                         ; exit w/EQ if "Big"
  1867.  
  1868.  
  1869. ; ================================================
  1870. GetRect
  1871. ; ================================================
  1872. ; Returns the rect in rectReg converted to global coordinates
  1873.  
  1874.             move.l    portRect(windowReg),topLeft(rectReg)           ; get locals
  1875.             move.l    portRect+botRight(windowReg),botRight(rectReg) ; get locals
  1876.             move.l    windowReg,A0        ; copy portPtr for PortToMap
  1877.             bsr        PortToMap            ; get the rect pointer
  1878.              move.l    rectReg,-(SP)        ; push address of rect
  1879.             move.l    bounds(A0),-(SP)    ; push offset locToGlob
  1880.             NEG.w    (SP)                ; make offset positive
  1881.             NEG.w    2(SP)
  1882.             _OffsetRect                 ; convert rect to global
  1883. GetRectDone    rts
  1884.  
  1885.  
  1886.  
  1887.  
  1888. ;----------------------------------------------------------------------------
  1889. ;
  1890. ; These routines are the heart of the WDEF’s ability to draw the right thing
  1891. ; on the right device based on the depth of the device. There are three kinds
  1892. ; of window color types we can draw:
  1893. ;
  1894. ;    Black and White        Drawn on non-CQD Macs, and on devices that have less
  1895. ;                        than 8 bits per pixel. 8 bits per pixel is a high,
  1896. ;                        arbitrary limit that we may be able to relax if we
  1897. ;                        can integrate use of the Palette Manager into the
  1898. ;                        WDEF.
  1899. ;    Custom wctbs        If there is a custom color table associated with
  1900. ;                        this window, then its colors are used. This may
  1901. ;                        change in the future if we find a way to customize
  1902. ;                        the colors of the System 7 three-d windows.
  1903. ;    System 7.0 & later    Our new default for color environments.
  1904. ;----------------------------------------------------------------------------
  1905.  
  1906. MakeRatioRGB
  1907.             movem.l    D7/A2, -(SP)
  1908.             lea        endRGB(A6), A0
  1909.             lea        startRGB(A6), A1
  1910.             lea        tempRGB(A6), A2
  1911.  
  1912.             mulu    #$1111, D2
  1913.  
  1914.             move.w    #2, D0
  1915. @nextChannel
  1916.             MOVEQ    #0, D1                    ; clear high word
  1917.             MOVE    (A0)+, D1                ; background color component
  1918.             SUB        (A1), D1                ; change from foreground
  1919.             SLO        D7                        ; remember if it was negated
  1920.             BHS.S    @orderedOK
  1921.             NEG        D1                        ; flip if subtraction would overflow
  1922. @orderedOK
  1923.             mulu    D2, D1                    ; multiply times scale factor
  1924.             SWAP    D1                        ; divide by 65K
  1925.             TST.B    D7
  1926.             BEQ.S    @notFlipped
  1927.             NEG.L    D1                        ; flip it
  1928. @notFlipped
  1929.             add.w    (A1)+, D1
  1930.             move.w    D1, (A2)+
  1931.             dbra    D0, @nextChannel
  1932.             movem.l    (SP)+, D7/A2
  1933.             rts
  1934.  
  1935.  
  1936. CheckAvailableColors
  1937. ;----------------------------------------------------------------------------
  1938. ; This routine is called just as we enter the _DeviceLoop drawing proc, after
  1939. ; the current depth has been stored in curDepth(A6). If the depth is 8 bits
  1940. ; per pixel or greater, and the wctb for this window is the default, then
  1941. ; we’re going to draw the System 7 three-d windows instead (threeDWind gets
  1942. ; set to TRUE). Otherwise, threeDWind gets set to FALSE.
  1943. ;----------------------------------------------------------------------------
  1944.             movem.l    D3-D4/A2, -(SP)                    ; these should be saved
  1945.             move.w    curDepth(A6), D0                ; how deep is the current device?
  1946.             cmp.w    #2, D0                            ; must be 2 bits/pixel or better
  1947.  
  1948.             sge        threeDWind(A6)                    ; set prelim answer
  1949.             blt.s    @exit                            ; get out if already no good
  1950.  
  1951.             move.l    TheGDevice, -(SP)                ; save this
  1952.             move.l    D1, TheGDevice                    ; set our device for color mapping
  1953.  
  1954.             tst.b    varCodeReg                        ; what kind of window is this?
  1955.             bz.s    @doCheckHilite
  1956.             tst.b    IsProcFive(A6)                    ; is it moveable modal?
  1957.             bne.s    @doneCheckHilite
  1958. @doCheckHilite
  1959.             lea        HiliteShades, A2                ; point at shades we need
  1960.             bsr.s    CheckShadesAvailable            ; see if all these shades are here
  1961.             tst.b    threeDWind(A6)                    ; did we fail to get the shades?
  1962.             bz.s    @colorExit                        ; get out if so
  1963.             lea        TitleBarShades, A2                ; point at shades we need
  1964.             bsr.s    CheckShadesAvailable            ; see if all these shades are here
  1965.             tst.b    threeDWind(A6)                    ; did we fail to get the shades?
  1966.             bz.s    @colorExit                        ; get out if so
  1967.             lea        TingeShades, A2                    ; point at shades we need
  1968.             bsr.s    CheckShadesAvailable            ; see if all these shades are here
  1969.             tst.b    threeDWind(A6)                    ; did we fail to get the shades?
  1970.             bz.s    @colorExit                        ; get out if so
  1971. @doneCheckHilite
  1972.             cmp.b    #dBoxProc, varCodeReg            ; do we need the thick dialog border?
  1973.             bne.s    @colorExit                        ; if not, we’re done checking
  1974.             lea        DialogShades, A2                ; point at shades we need
  1975.             bsr.s    CheckShadesAvailable            ; see if all these shades are here
  1976. @colorExit
  1977.             move.l    (SP)+, TheGDevice                ; restore device
  1978. @exit
  1979.             movem.l    (SP)+, D3-D4/A2
  1980.             rts
  1981.  
  1982. CheckShadesAvailable
  1983.             move.w    (A2), D3                        ; get next ‘light’ color
  1984.             move.l    #'csd ', D4                        ; an unlikely pixel value
  1985. @rampLoop
  1986.             cmp        (A2), D3                        ; get the next shade’s light color
  1987.             bne.s    @exit                            ; if new, reinit for new ramp
  1988.             move.l    A2, A0                            ; point to shade entry
  1989.             bsr        SetupRatioColor                    ; get shade in tempRGB
  1990.             subq.l    #4, SP                            ; room for pixel index
  1991.             pea        tempRGB(A6)                        ; the shade RGB we want
  1992.             _Color2Index                            ; what does it map to?
  1993.             move.l    (SP)+, D0                        ; get the pixel index
  1994.             cmp.l    D0, D4                            ; is it the same as last time?
  1995.             beq.s    @failure                        ; if so, not enough colors
  1996.             move.l    D0, D4                            ; update ‘last’ shade index
  1997.             addq.l    #6, A2                            ; point to next shade
  1998.             bra.s    @rampLoop                        ; and test it
  1999. @failure
  2000.             sf        threeDWind(A6)                    ; use the old kind
  2001. @exit
  2002.             rts
  2003.  
  2004. DefaultWCTB
  2005. ;----------------------------------------------------------
  2006. ; This table of bytes represents the colors in the default
  2007. ; wctb. It uses bytes because we know that the default
  2008. ; table only has black and white.
  2009. ;----------------------------------------------------------
  2010.             dc.b    $FF, $00, $00, $00, $FF, $00, $00, $FF
  2011.             dc.b    $FF, $00, $00, $00, $00, $00, $00, $00
  2012.             dc.b    $00, $00, $00, $00, $00, $FF, $FF, $FF
  2013.             dc.b    $FF, $FF, $FF, $00, $00, $00, $00, $00
  2014.             dc.b    $00, $FF, $FF, $FF, $FF
  2015.             align
  2016.  
  2017. SetupRatioColor
  2018.             move.w    4(A0), -(SP)                        ; push shade percent
  2019.             move.w    2(A0), -(SP)                        ; push dark (to/fore) end of shade
  2020.             move.w    (A0), D0                            ; get light shade color number
  2021.             bsr.s    SetUpColor                            ; get the color of the light (from/back) end
  2022.             move.l    (SP)+, A0                            ; get pointer to light color
  2023.             move.l    (A0)+, startRGB(A6)                    ; copy red and green
  2024.             move.w    (A0), startRGB+4(A6)                ; copy blue
  2025.             move.w    (SP)+, D0                            ; get dark color number
  2026.             bsr.s    SetUpColor                            ; get the color of the light end
  2027.             move.l    (SP)+, A0                            ; get pointer to light color
  2028.             move.l    (A0)+, endRGB(A6)                    ; copy red and green
  2029.             move.w    (A0), endRGB+4(A6)                    ; copy blue
  2030.             move.w    (SP)+, D2                            ; get shade percentage
  2031.             bsr.s    MakeRatioRGB                        ; create a shade between the two
  2032.             rts
  2033.  
  2034. ; ================================================
  2035. SetupColors
  2036. ; ================================================
  2037. ; Added this routine to help setup fore- and back color and save code.
  2038. ; SetUpColor takes a fore color in D0, and a back color in D1.
  2039. ; It then calls SetUpColor with both of them (which likes its
  2040. ; parameter in D0), and calls RGBForeColor and RGBBackColor
  2041. ; where appropriate.
  2042.  
  2043.             move.w    D1,-(SP)            ; save part identifier of back color
  2044.             bsr.s    SetupForeColor
  2045.             move.w    (SP)+,D0            ; get saved part
  2046.             bsr.s    SetupBackColor
  2047.             rts                            ; all done
  2048.  
  2049. ; ================================================
  2050. SetupForeColor
  2051. ; ================================================
  2052.  
  2053.             bsr.s    SetUpColor            ; D0 has forecolor part identifier
  2054.             bz.s    @setClassicFore        ; if non-CQD answer, branch
  2055.             _RGBForeColor
  2056.             bra.s    @exit
  2057. @setClassicFore
  2058.             _ForeColor
  2059. @exit
  2060.             rts                                            ; all done
  2061.  
  2062. ; ================================================
  2063. SetupBackColor
  2064. ; ================================================
  2065.  
  2066.             bsr.s    SetUpColor            ; D0 has forecolor part identifier
  2067.             bz.s    @setClassicBack        ; if non-CQD answer, branch
  2068.             _RGBBackColor
  2069.             bra.s    @exit
  2070. @setClassicBack
  2071.             _BackColor
  2072. @exit
  2073.             rts                                            ; all done
  2074.  
  2075. ; ================================================
  2076. SetUpColor
  2077. ; ================================================
  2078. ; SetUpColor takes a window part identifier in D0, finds the corresponding
  2079. ;    part in the AuxWinTable (the part code is in the .value field) and returns
  2080. ;    a pointer to its RGB on the stack.  If the requested part is not found,
  2081. ;    the old black and white color for that part is used.
  2082.  
  2083.             tst.b    threeDWind(A6)                        ; can we use System 7 windows?
  2084.             bz.s    @useBlackAndWhite                    ; nope? Try other cases
  2085.             cmp.w    #lowestShadeIndex, D0                ; is this a shade color?
  2086.             blt.s    @notShade                            ; not a shade color
  2087.             sub.w    #lowestShadeIndex, D0                ; normalize to shade colors
  2088.             mulu    #6, D0                                ; x6 for table index
  2089.             lea        ShadeTable, A0                        ; point at table of shade colors
  2090.             add.w    D0, A0                                ; point to correct entry
  2091.             bsr.s    SetupRatioColor                        ; get color in tempRGB
  2092.             move.l    (SP)+, A0                            ; pop the return address
  2093.             pea        tempRGB(A6)                            ; point to rgb color
  2094.             moveq    #1, D0                                ; indicate color answer
  2095.             jmp        (A0)                                ; get outa here
  2096.  
  2097. @notShade
  2098.             move.l    AuxCPtr(A6), A0                        ; get the color table pointer
  2099.             bsr        GoodColorTable                        ; does ctb contain the index (in D0)?     
  2100.             beq.s    @foundIt                            ; yes => go return corresponding color     
  2101.             move.w    D0,-(SP)                            ; save the index to color table on stack 
  2102.             subq.l    #4,SP                                ; leave space for results                 
  2103.             move.l    #'wctb',-(SP)                        ; try to get the system wctb             
  2104.             clr.w    -(SP)                                ;                                         
  2105.             _GetResource                                ;                                         
  2106.             move.l    (SP)+,A0                            ; get the wctb resource                     
  2107.             move.w    (SP)+,D0                            ; retrieve the index                     
  2108.             cmp.l    #0,A0                                ; did we really get the wctb resource     
  2109.             beq.s    @useDefaultCTab                        ; no =>    go use the default ctab             
  2110.             move.l    (A0),A0                                ; yes => deference to get ptr to wctb     
  2111.             bsr        GoodColorTable                        ; does wctb contain the index (in D0)?     
  2112.             beq.s    @foundIt                            ; yes => go return corresponding color     
  2113. @useDefaultCTab                                            ; no => use the default ctab             
  2114.             mulu    #6,D0                                ; (x6) index into rgb specs
  2115.             lea        ThreeDColors, A0                    ; point at standard colors
  2116. @getCorrectColor                                        ;                                         
  2117.             move.l    (SP)+,D1                            ; get return address                     
  2118.             pea        (A0, D0.w)                            ; point at correct color
  2119.             move.l    D1, A0                                ; get return address
  2120.             bra.s    @exitColor
  2121. @foundIt
  2122.             lea        ctTable+rgb(A0, D1), A0             ; get the address of the color to use
  2123.             move.l    A0, D0                                ; we’ll need A0 in a second
  2124.             move.l    (SP)+, A0                            ; get the return address
  2125.             move.l    D0, -(SP)                            ; push the rgb addr on the stack
  2126. @exitColor
  2127.             moveq    #1, D0                                ; indicate color answer
  2128.             jmp        (A0)                                ; return to caller
  2129.  
  2130. @useBlackAndWhite
  2131.             lea        DefaultWCTB, A0                        ; point to cheesy color table
  2132.             move.b    (A0, D0.w), D0                        ; get white or black (as a byte)
  2133.             bnz.s    @simpleWhite                        ; branch if we want white
  2134.             moveq    #blackColor, D0                        ; get the old-style color
  2135.             bra.s    @classicExit                        ; get outa here
  2136. @simpleWhite
  2137.             moveq    #whiteColor, D0                        ; get old-style white
  2138. @classicExit
  2139.             move.l    (SP)+, A0                            ; return address
  2140.             move.l    D0, -(SP)                            ; classic color
  2141.             moveq    #0, D0                                ; indicate classic answer
  2142.             jmp        (A0)
  2143. * •••• NOTE:  SetupColorPict is not included in this example.
  2144. *  SetupColorPict uses private, undocumented, and highly unstable
  2145. * resources in the system file.
  2146. * You really don't need them, since the bitmap and iconic 
  2147. * representations of the window gadgets is/are included at the end 
  2148. * of this file, and you can design your own PICT type resource to do the same 
  2149. * thing.  
  2150.  
  2151. SetupColorPict
  2152.             rts
  2153.  
  2154. GoodColorTable
  2155.             move.w    ctSize(A0), D1                        ; get the color table size
  2156.             asl.w    #3, D1                                ; (x8) convert to color table index
  2157. @legalIndex
  2158.             cmp.w    ctTable+value(A0,D1), D0            ; is this the one?
  2159.             beq.s    @done                                ; if equal, then done
  2160.             subq.w    #8, D1                                ; try the previous one
  2161.             bge.s    @legalIndex                            ; loop while index positive
  2162. @done
  2163.             rts
  2164.  
  2165. ; ================================================
  2166. PortToMap                                        ;  
  2167. ; ================================================
  2168. ; Given a window pointer in A0, return the bitmap/pixmap pointer in A0
  2169.  
  2170.             addq    #portBits,A0                ;POINT TO BITMAP/PIXMAP HANDLE
  2171.             tst        rowBytes(A0)                ;BITMAP OR PIXMAP HANDLE?
  2172.             bpl.s    GotBitMap                    ;=>JUST A BITMAP
  2173.             move.l    baseAddr(A0),A0                ;ELSE GET PORT’S PIXMAP HANDLE
  2174.             move.l    (A0),A0                        ;GET PIXMAP POINTER
  2175. GotBitMap    rts
  2176.  
  2177.  
  2178. ; ================================================
  2179. ; CONSTANTS
  2180. ; ================================================
  2181. ; some data used in the WDEF
  2182.  
  2183. ; ------------- HilitePattern used in the title bar -------------
  2184. HilitePattern
  2185.             dc.w    $FF00,$FF00,$FF00,$FF00
  2186.  
  2187. PixelRsrcIDs
  2188. ;----------------------------------------------------------
  2189. ; This is a table of resource IDs for the PICTs which are
  2190. ; used to draw the small pieces of the System 7 windows.
  2191. ;----------------------------------------------------------
  2192.             dc.w    -14335                            ; wZoomGadget
  2193.             dc.w    -14335                            ; wGoAwayGadget
  2194.             dc.w    -14334                            ; wZoomGadgetHighlight
  2195.             dc.w    -14334                            ; wGoAwayGadgetHighlight
  2196.             dc.w    -14335                            ; wGrowGadget
  2197.  
  2198. ThreeDColors
  2199. ;-----------------------------------------------------------
  2200. ; These are the RGB colors which are used to draw the shaded
  2201. ; windows.
  2202. ;-----------------------------------------------------------
  2203.             dc.w    $FFFF, $FFFF, $FFFF                ; wContentColor
  2204.             dc.w    $0000, $0000, $0000                ; wFrameColor
  2205.             dc.w    $0000, $0000, $0000                ; wTextColor
  2206.             dc.w    $0000, $0000, $0000                ; wHiliteColor (not used)
  2207.             dc.w    $FFFF, $FFFF, $FFFF                ; wTitleBarColor (not used)
  2208.             dc.w    $FFFF, $FFFF, $FFFF                ; wHiliteLight
  2209.             dc.w    $0000, $0000, $0000                ; wHiliteDark
  2210.             dc.w    $FFFF, $FFFF, $FFFF                ; wTitleBarLight
  2211.             dc.w    $0000, $0000, $0000                ; wTitleBarDark
  2212.             dc.w    $CCCC, $CCCC, $FFFF                ; wDialogLight
  2213.             dc.w    $0000, $0000, $0000                ; wDialogDark
  2214.             dc.w    $CCCC, $CCCC, $FFFF                ; wTingeLight
  2215.             dc.w    $3333, $3333, $6666                ; wTingeDark
  2216.  
  2217. ShadeTable
  2218. HiliteShades
  2219.             dc.w    wHiliteLight, wHiliteDark, $0        ; wHiliteShade0
  2220.             dc.w    wHiliteLight, wHiliteDark, $7        ; wHiliteShade7
  2221.             dc.w    wHiliteLight, wHiliteDark, $8        ; wHiliteShade8
  2222.             dc.w    wHiliteLight, wHiliteDark, $A        ; wHiliteShadeA
  2223.             dc.w    wHiliteLight, wHiliteDark, $D        ; wHiliteShadeD
  2224. TitleBarShades
  2225.             dc.w    wTitleBarLight, wTitleBarDark, $0    ; wTitleBarShade0
  2226.             dc.w    wTitleBarLight, wTitleBarDark, $1    ; wTitleBarShade1
  2227.             dc.w    wTitleBarLight, wTitleBarDark, $4    ; wTitleBarShade4
  2228. DialogShades
  2229.             dc.w    wDialogLight, wDialogDark, $0        ; wDialogShade0w
  2230.             dc.w    wDialogLight, wDialogDark, $4        ; wDialogShade4w
  2231.             dc.w    wDialogLight, wDialogDark, $6        ; wDialogShade6w
  2232.             dc.w    wDialogLight, wDialogDark, $B        ; wDialogShadeBb
  2233.             dc.w    wDialogLight, wDialogDark, $F        ; wDialogShadeF
  2234.             dc.w    0, 0, 0                                ; stop checking shades
  2235.             dc.w    wDialogLight, wDialogDark, $0        ; wDialogShade0b
  2236.             dc.w    wDialogLight, wDialogDark, $4        ; wDialogShade4b
  2237.             dc.w    wDialogLight, wDialogDark, $6        ; wDialogShade6b
  2238.             dc.w    wDialogLight, wDialogDark, $B        ; wDialogShadeBw
  2239. TingeShades
  2240.             dc.w    wTingeLight, wTitleBarDark, $0        ; wLTinge0
  2241.             dc.w    wTingeLight, wTingeDark, $4            ; wLTinge4                     
  2242.             dc.w    wTitleBarLight, wTingeDark, $F        ; wDTingeF
  2243. EndOfShades
  2244.             dc.w    0
  2245.  
  2246. BorderShades
  2247.             dc.w    wDialogShade6w, wDialogShade0w        ; Border colors for active windows
  2248.             dc.w    wDialogShade6w, wTitleBarShade4
  2249.             dc.w    wDialogShade0b, wDialogShade6b
  2250.             dc.w    wDialogShade6b, wDialogShadeF
  2251.  
  2252.             dc.w    wTitleBarShade0, wTitleBarShade0        ; Border colors for inactive windows
  2253.             dc.w    wTitleBarShade0, wTitleBarShade0
  2254.             dc.w    wHiliteShade8, wHiliteShade8
  2255.             dc.w    wHiliteShade8, wHiliteShade8
  2256.  
  2257. BitmapOffsets
  2258. ;----------------------------------------------------------
  2259. ; This is a table of words which represent the offsets
  2260. ; from WDEFBitmaps to the beginning of each bitmap
  2261. ;----------------------------------------------------------
  2262.             dc.w    ZoomData-BitmapOffsets
  2263.             dc.w    GoAwayData-BitmapOffsets
  2264.             dc.w    ZoomHiliteData-BitmapOffsets
  2265.             dc.w    GoAwayHiliteData-BitmapOffsets
  2266.             dc.w    GrowBits-BitmapOffsets
  2267.  
  2268. WDEFBitmaps
  2269. ;----------------------------------------------------------
  2270. ; These bitmaps are used when drawing on classic QD
  2271. ; machines, or when the bit depth is too low to draw in
  2272. ; color.
  2273. ;----------------------------------------------------------
  2274.  
  2275.  
  2276. ; ------------- ZoomData used in the zoom box -------------
  2277. ZoomData
  2278.  
  2279.             dc.w    $0002                        ; rowBytes
  2280.             dc.w    $0000, $0000, $000B, $000B    ; bounds
  2281.             dc.w    $FFE0                        ; •••••••••••.....
  2282.             dc.w    $8220                        ; •.....•...•.....
  2283.             dc.w    $8220                        ; •.....•...•.....
  2284.             dc.w    $8220                        ; •.....•...•.....
  2285.             dc.w    $8220                        ; •.....•...•.....
  2286.             dc.w    $8220                        ; •.....•...•.....
  2287.             dc.w    $FE20                        ; •••••••...•.....
  2288.             dc.w    $8020                        ; •.........•.....
  2289.             dc.w    $8020                        ; •.........•.....
  2290.             dc.w    $8020                        ; •.........•.....
  2291.             dc.w    $FFE0                        ; •••••••••••.....
  2292.  
  2293. ZoomHiliteData
  2294. GoAwayHiliteData
  2295.             dc.w    $0002                        ; rowBytes
  2296.             dc.w    $0000, $0000, $000B, $000B    ; bounds
  2297.  
  2298.             dc.w    $FFE0                        ; •••••••••••.....
  2299.             dc.w    $8420                        ; •....•....•.....
  2300.             dc.w    $A4A0                        ; •.•..•..•.•.....
  2301.             dc.w    $9520                        ; •..•.•.•..•.....
  2302.             dc.w    $8020                        ; •.........•.....
  2303.             dc.w    $F1E0                        ; ••••...••••.....
  2304.             dc.w    $8020                        ; •.........•.....
  2305.             dc.w    $9520                        ; •..•.•.•..•.....
  2306.             dc.w    $A4A0                        ; •.•..•..•.•.....
  2307.             dc.w    $8420                        ; •....•....•.....
  2308.             dc.w    $FFE0                        ; •••••••••••.....
  2309.  
  2310. ; ------------- BitMap for default GoAway button -------------
  2311. GoAwayData
  2312.  
  2313.             dc.w    $0002                        ; rowBytes
  2314.             dc.w    $0000, $0000, $000B, $000B    ; bounds
  2315.             dc.w    $FFE0                        ; •••••••••••.....
  2316.             dc.w    $8020                        ; •.........•.....
  2317.             dc.w    $8020                        ; •.........•.....
  2318.             dc.w    $8020                        ; •.........•.....
  2319.             dc.w    $8020                        ; •.........•.....
  2320.             dc.w    $8020                        ; •.........•.....
  2321.             dc.w    $8020                        ; •.........•.....
  2322.             dc.w    $8020                        ; •.........•.....
  2323.             dc.w    $8020                        ; •.........•.....
  2324.             dc.w    $8020                        ; •.........•.....
  2325.             dc.w    $FFE0                        ; •••••••••••.....
  2326.  
  2327. ; ------------- BitMap for GrowIcon -------------
  2328. GrowBits
  2329.             dc.w    $0002                        ; rowBytes
  2330.             dc.w    $0000, $0000, $000F, $000F    ; bounds
  2331.             dc.w    $0000                        ; ................
  2332.             dc.w    $0000                        ; ................
  2333.             dc.w    $0000                        ; ................
  2334.             dc.w    $1FC0                        ; ...•••••••......
  2335.             dc.w    $1040                        ; ...•.....•......
  2336.             dc.w    $107C                        ; ...•.....•••••..
  2337.             dc.w    $1044                        ; ...•.....•...•..
  2338.             dc.w    $1044                        ; ...•.....•...•..
  2339.             dc.w    $1044                        ; ...•.....•...•..
  2340.             dc.w    $1FC4                        ; ...•••••••...•..
  2341.             dc.w    $0404                        ; .....•.......•..
  2342.             dc.w    $0404                        ; .....•.......•..
  2343.             dc.w    $0404                        ; .....•.......•..
  2344.             dc.w    $07FC                        ; .....•••••••••..
  2345.             dc.w    $0000                        ; ................
  2346.  
  2347.             END
  2348.